Skip to content

Instantly share code, notes, and snippets.

@victorshkoda
Created April 14, 2020 07:01
Show Gist options
  • Save victorshkoda/dff2cda4a1fccd6efbf463db2ffe72ad to your computer and use it in GitHub Desktop.
Save victorshkoda/dff2cda4a1fccd6efbf463db2ffe72ad to your computer and use it in GitHub Desktop.
simple express server
/*
* package.json
* "express": "^4.16.4",
* "serve-static": "^1.13.2"
* */
const express = require('express');
const serveStatic = require("serve-static");
const port = process.env.PORT || 5000;
const path = require('path');
const app = express();
app.use(function (req, res, next) {
res.header('X-powered-by', 'Blood, sweat, and tears')
res.header('Cache-Control', 'no-cache')
res.header('Access-Control-Allow-Origin', req.headers.origin)
res.header('Access-Control-Allow-Credentials', true)
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
next();
});
app.use(serveStatic(path.join(__dirname, 'dist')));
app.listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment