Last active
February 20, 2020 03:53
-
-
Save victorshkoda/dfac557a6e626c7b173e749f3586a4a6 to your computer and use it in GitHub Desktop.
Simple expressjs 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