Node.js的(v0.10.15) 的package.json "dependencies": {"express": "~3.3.5","express-namespace": "~0.1.1",}, app.coffee ...app = module.exports = express()server = http.createServer(app)app.configure () - app.use express.compress() app.use ex
的package.json
"dependencies": { "express": "~3.3.5", "express-namespace": "~0.1.1", },
app.coffee
... app = module.exports = express() server = http.createServer(app) app.configure () -> app.use express.compress() app.use express.bodyParser() app.use express.cookieParser() app.use express.favicon() app.use express.session({secret: '343453wEFsda'}) app.use express.static( __dirname + '/public') app.use app.router (require('./routes'))(app) app.listen(3000);
routes.coffee
test1 = (req, res,next) -> console.log("twice? what the...") next(); test = (req, res, next) -> console.log("once!"); next(); routes = (app) -> app.namespace '/', test1, -> app.get '/', test, (req, res) -> res.send(''); app.post '/', (req, res) -> res.send(''); module.exports = routes
请求的服务器日志如下:
twice? what the... twice? what the... once!
它不知道为什么中间件在单个请求上调用了两次?
你见过那样的吗?
如果您使用浏览器进行测试,则浏览器可能会在查找favicon.ico时发出第二个请求.尝试使用curl / wget.