使用中间件功能。这样,robots.txt将在任何会话,cookieParser等之前进行处理:
app.use('/robots.txt', function (req, res, next) { res.type('text/plain') res.send("User-agent: *nDisallow: /");});app.get现在,借助express 4 可以按显示顺序处理它,因此您可以使用它:
app.get('/robots.txt', function (req, res) { res.type('text/plain'); res.send("User-agent: *nDisallow: /");});


