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

时间:2014-10-14 23:56:17

标签: javascript node.js express

我不确定如何对此进行说明,但由于缺少适当的术语,以下代码的一部分不起作用。如果我尝试转到localhost:3000/,则不会发回回复。我正在使用Express 4.7.4和Ubuntu Trusty存储库上提供的最新节点。

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');
});

1 个答案:

答案 0 :(得分:0)

通过将Express更新到4.9版来修复。

修改:如the documentation中所述,我做错了。