Last active
December 16, 2015 20:19
-
-
Save Naouak/5491699 to your computer and use it in GitHub Desktop.
Serving static content on dynamic url with expressjs
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
//Create a module for static middleware instanciation with a singleton | |
//Use the same singleton for app.use and variable routing. | |
//If there is some caching stuff going on, they should share the same cache which is a lot better. | |
var express = require("express"); | |
var static = null; | |
module.exports = function(){ | |
if(!static){ | |
static = express.static(__dirname+"/public"); | |
} | |
return static; | |
} |
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
module.exports = function(req,res,next){ | |
var static = express.static(__dirname+"/public"); | |
req.method = "GET"; | |
req.url = "/mystaticcontent.html"; | |
static(req,res,next); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment