Last active
December 14, 2015 19:19
-
-
Save pdswan/5135567 to your computer and use it in GitHub Desktop.
express cors
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
var express = require('express') | |
, cors = require('connect-xcors')({ | |
headers: ['X-Requested-With', 'X-HTTP-Method-Override', 'Content-Type', 'Accept', 'Authorization'] | |
}) | |
var app = express() | |
// OPTIONS requests don't get handled because | |
// cors is hidden behind the routing middleware | |
// and '/' is only accessible via GET | |
// NOTE: using `app.all` here makes this work | |
// as intended. the other option is to use an | |
// empty OPTIONS request: `app.options('/', [cors], function(req, res) { })` | |
app.get('/', [cors], function(req, res) { | |
res.end('ok') | |
}) | |
app.listen(3000) |
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
var express = require('express') | |
, cors = require('connect-xcors')({ | |
headers: ['X-Requested-With', 'X-HTTP-Method-Override', 'Content-Type', 'Accept', 'Authorization'] | |
}) | |
var app = express() | |
app.use(cors) | |
app.get('/', function(req, res) { | |
res.end('ok') | |
}) | |
app.listen(3000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment