Skip to content

Instantly share code, notes, and snippets.

@bera5186
Created December 15, 2020 12:52
Show Gist options
  • Save bera5186/f3116f902746ad3d74e4157fe3ef3fc4 to your computer and use it in GitHub Desktop.
Save bera5186/f3116f902746ad3d74e4157fe3ef3fc4 to your computer and use it in GitHub Desktop.
Express api headers for CORS.
const express = require("express")
const app = express();
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment