Last active
December 15, 2015 21:28
-
-
Save tivac/bcf81a050e154b3ae02d to your computer and use it in GitHub Desktop.
Dumb static SPA server
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
"use strict"; | |
var path = require("path"), | |
server = require("connect")(), | |
ecstatic = require("ecstatic")(process.cwd(), { | |
cache : 0, | |
handleError : false | |
}); | |
server.use(function(req, res, next) { | |
console.log(req.url); | |
next(); | |
}); | |
server.use(ecstatic); | |
// SPA support | |
server.use(function(req, res, next) { | |
if(path.extname(req.url)) { | |
res.code = 404; | |
return next("Unknown file"); | |
} | |
req.url = "/"; | |
ecstatic(req, res, next); | |
}); | |
server.listen(9966); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment