Last active
August 29, 2015 13:58
-
-
Save jfromaniello/10021643 to your computer and use it in GitHub Desktop.
This file contains 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
function onlyStatic (middleware) { | |
return function (req, res, next) { | |
var match = /(\.css|\.eot|\.gif|\.html|\.js|\.png|\.svg|\.ttf|\.woff|\.jpg)($|\?.*$)/ig.exec(req.originalUrl); | |
if (!match) return next(); | |
middleware(req, res, next); | |
}; | |
} | |
//usage | |
this.use(onlyStatic(express.static(__dirname + "/public"))); |
@molokoloco haha good catch
Actually this regex fails if you have a request like:
/foo?file=x.html
<< this is not static
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't like JPG ? :)