Created
April 14, 2020 07:01
-
-
Save victorshkoda/dff2cda4a1fccd6efbf463db2ffe72ad to your computer and use it in GitHub Desktop.
simple express server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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