Skip to content

Instantly share code, notes, and snippets.

@mtinra
Last active May 2, 2019 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtinra/e5cd4f12fb6d041daeade67e2689fa73 to your computer and use it in GitHub Desktop.
Save mtinra/e5cd4f12fb6d041daeade67e2689fa73 to your computer and use it in GitHub Desktop.
basic express server with CORS header
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