您的静态文件中间件应该优先。
app.use(express.static(__dirname + '/public'));app.use(express.bodyParser());app.use(express.cookieParser());app.use(express.session({secret: 'secret'}));并且您还应该为app.router添加用途。
app.use(express.static(__dirname + '/public'));app.use(express.bodyParser());app.use(express.cookieParser());app.use(express.session({secret: 'secret'}));app.use(app.router);中间件按顺序处理每个请求。因此,如果您
index.html的静态文件中有个,则对的请求
yourdomain.com/将永远不会到达,
app.router因为它们将由静态文件处理程序处理。删除
index.html,然后该请求将通过您的
app.router。



