loopbackjs - Change Express static path dynamically -


in express setup static folder serve files through middleware. have understood set throughout applications lifecycle.

is possible set somewhere in server.js each request instead? instance requests uses "clientnew" folder while other requests uses "client". want able see difference through session-id, not through url.

so while not recommended approach "open" application lots of users due optimization caching , response time solved doing pointer static handler.

exports.createdynamicpath = function(app, path) {   var static = app.loopback.static(path, { etag: false});   var dynamicpath = function (req, res, next) {     return static(req, res, next);   }   dynamicpath.setpath = function (newpath) {     static = app.loopback.static(newpath, { etag: false})   }   return dynamicpath; }  exports.determineclient = function(app, dynamicpath){   return function(req, res, next) {     if(req.cookies && req.cookies.version != "client2"){       dynamicpath.setpath("client");     }else{       dynamicpath.setpath("client2");     }     next();   } } 

based upon variable in cookies switches path. worth noting disabling of etag, critical due browsers storing previous client , determining if file still viable keep.

this code used app, in case loopback (which core uses express).


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -