1 thought on “Serve static files based on changing config file at runtime

  1. I would suggest that unless this is a bug report or issue with Express, we should probably move the discussion to the support area https://gitter.im/expressjs/express

    That said, I would like to add my thoughts here as well 🙂

    From the conversation above, I believe I understand what you’re trying to accomplish, which sounds like you want to basically have a app.use(express.static(path)) and then at runtime, be able to alter that path variable to cause static files to switch to another version of your assets. Without getting into the different merits of all the different pros and cons of versioning assets, managing, and switching between them, I’ll just focus on a very simple implementation of this request in Express:

    var dyn = createDynStatic(path)
    app.use(dyn) // setup your static here
    // you would POST /switch/1.0
    // to start serving from public/1.0/
    app.post('/switch/:version', function (req, res) {
      dyn.setPath('public/' + req.params.version)
    function createDynStatic (path) {
      var static = express.static(path)
      var dyn = function (req, res, next) {
        return static(req, res, next)
      dyn.setPath = function (newPath) {
        static = express.static(newPath)
      return dyn

Comments are closed.