How to configure dynamic routes with express.js

前端 未结 7 2375
Happy的楠姐
Happy的楠姐 2020-12-07 20:32

I have a route.js which looks like this:

module.exports = function(app) {

  app.get(\'/tip\', function(req, res) {
    res.render(\"tip\");
  });

  app.get         


        
7条回答
  •  太阳男子
    2020-12-07 20:36

    It's work on my project

    routesPath = path.join(__dirname, 'routes');
    
    fs.readdirSync(routesPath).forEach(function(file) {
      require(routesPath + '/' + file)(app);
    });
    

提交回复
热议问题