简体   繁体   English

ExpressJS app.use(“ /”路由器)router.get(“ /”)中断

[英]ExpressJS app.use(“/” router) router.get(“/”) Breaks

I'm not sure how to phrase this, but part of the following code, for lack of an appropriate term, doesn't work. 我不确定该如何表达,但是由于缺少适当的术语,下面的代码部分无法正常工作。 If I try to go to localhost:3000/ it doesn't send back a response. 如果我尝试转到localhost:3000/ ,则不会发送回响应。 I'm using Express 4.7.4 and the latest node available on the Ubuntu Trusty repository. 我正在使用Express 4.7.4和Ubuntu Trusty存储库中可用的最新节点。

app.js app.js

 ///// Dependencies & config var express = require('express'); ///// Bootstrapping //// Prepare Express var server = express(); /// Configure Express server.set('views', __dirname + '/views'); /// Routers var infoR = express.Router(); // This doesn't send anything back infoR.get("/", function(req, res) { res.render('common/home'); }); // This works perfectly infoR.get("/something", function(req, res) { res.render('info/something'); }); // Routes that work server.use('/admin', require('./routes/admin')); server.use('/account', require('./routes/account')); server.use('/', infoR); // This is where the problem starts ///// Start the server server.listen(3000, function() { console.log('Server started on port 3000'); }); 

Fixed by updating Express to version 4.9. 已通过将Express更新到4.9版修复。

Edit : Turns out I've been doing it wrong, as noted in the documentation . 编辑 :原来我做错了,如文档所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM