Created
June 21, 2013 13:16
-
-
Save ahmednuaman/5831055 to your computer and use it in GitHub Desktop.
CORS server in less than 33 lines (NodeJS)
This file contains hidden or 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'); | |
var fs = require('fs'); | |
var app = express(); | |
var port = 8000; | |
app.configure(function() { | |
app.use(function(request, response, next) { | |
response.header('Access-Control-Allow-Origin', '*'); | |
response.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); | |
response.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With, API-Key'); | |
next(); | |
}); | |
app.use('/', express.static(__dirname + '/')); | |
}); | |
app.use(express.bodyParser()); | |
app.use(express.logger()); | |
app.options('*', function(request, response, next) { | |
response.send(200); | |
}); | |
app.get('*', function(request, response, next) { | |
response.redirect('/index.html'); | |
}); | |
app.listen(port, function() { | |
console.log('Listening on port: ' + port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment