Skip to content

Instantly share code, notes, and snippets.

@ahmednuaman
Created June 21, 2013 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmednuaman/5831055 to your computer and use it in GitHub Desktop.
Save ahmednuaman/5831055 to your computer and use it in GitHub Desktop.
CORS server in less than 33 lines (NodeJS)
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