我目前正在使用Express(Node.js)构建的应用程序,我想知道在不同环境(开发,生产)下处理不同robots.txt的最聪明方法是什么。
这是我现在所拥有的,但是我对解决方案不满意,我认为它很脏:
app.get '/robots.txt', (req, res) ->
res.set 'Content-Type', 'text/plain'
if app.settings.env == 'production'
res.send 'User-agent: *\nDisallow: /signin\nDisallow: /signup\nDisallow: /signout\nSitemap: /sitemap.xml'
else
res.send 'User-agent: *\nDisallow: /'
(注意:这是CoffeeScript)
应该有更好的方法。你会怎么做?
谢谢。
app.use('/robots.txt', function (req, res, next) { ... });
并失去req.url
支票是有意义的。