Skip to content

Instantly share code, notes, and snippets.

@pdswan
Last active December 14, 2015 19:19
Show Gist options
  • Save pdswan/5135567 to your computer and use it in GitHub Desktop.
Save pdswan/5135567 to your computer and use it in GitHub Desktop.
express cors
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)
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