Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cors on Express #138

Open
devconcept opened this issue Nov 30, 2018 · 0 comments
Open

Cors on Express #138

devconcept opened this issue Nov 30, 2018 · 0 comments

Comments

@devconcept
Copy link

The "CORS for node and express page" is more complicated and less configurable than it should be. There is a cors module for node that works with express middleware and it is referenced in the docs. You can configure CORS per route, router or app and it has a lot of configuration options.

Instead of

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();
});

You could simply do

var cors = require('cors');

app.use(cors());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant