Express sendfile and redirect url

前端 未结 1 1109
粉色の甜心
粉色の甜心 2021-01-14 06:48

I have a bunch of middleware. At the first app.use I test if the process is under duress, and if so I want it to just send the static /index.html f

相关标签:
1条回答
  • 2021-01-14 07:36

    Not sure if I understand correctly, but try this:

    app.use(function(req, res, next) {
      if (something && req.path !== '/')
        return res.redirect('/');
      next();
    });
    
    app.get('/', function(req, res, next) {
      if (something)
        return res.sendfile('/public/index.html', { root: __dirname + '/..' });
      next();
    });
    
    app.use(express.static(...));
    
    0 讨论(0)
提交回复
热议问题