Last active
May 2, 2019 09:13
-
-
Save mtinra/e5cd4f12fb6d041daeade67e2689fa73 to your computer and use it in GitHub Desktop.
basic express server with CORS header
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
const express = require("express"); | |
const app = express(); | |
const port = process.env.SERVER_PORT || 3000; | |
app.use(function(req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header( | |
"Access-Control-Allow-Headers", | |
"Origin, X-Requested-With, Content-Type, Accept" | |
); | |
next(); | |
}); | |
app.get("/api/ping", (req, res) => { | |
res.send({ | |
msg: "Hello, World" | |
}); | |
}); | |
app.listen(port, () => console.log(`Listening on port ${port}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment