node.js(v0.10.15)
包.json
"dependencies": {
"express": "~3.3.5",
"express-namespace": "~0.1.1",
},
应用程序.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);
路线.咖啡
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!
它不知道为什么中间件在单个请求上调用两次?
你见过这样的吗?