Skip to content

Instantly share code, notes, and snippets.

@spearwolf
Created April 1, 2015 11:23
Show Gist options
  • Select an option

  • Save spearwolf/cf586c2d57e07c99d526 to your computer and use it in GitHub Desktop.

Select an option

Save spearwolf/cf586c2d57e07c99d526 to your computer and use it in GitHub Desktop.
http static file server: cors enabled
// npm install finalhandler serve-static
var finalhandler = require('finalhandler');
var http = require('http');
var serveStatic = require('serve-static');
var serve = serveStatic('./', {
'index': false,
'setHeaders': setHeaders
});
function setHeaders(res) { //, path) {
res.setHeader('Access-Control-Allow-Origin', '*');
}
var server = http.createServer(function(req, res){
var done = finalhandler(req, res);
serve(req, res, done);
});
server.listen(9999);
console.log('listening to http://localhost:9999/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment