在升级到 Express 4 并删除 app.router 之后,我正在努力让中间件在路由执行后执行。
例如,以下代码正确响应“hello”,但从不调用配置的中间件
var express = require( "express" )();
express.get( "/", function( req, res ) {
res.send( "hello" );
} );
express.use( function( req, res, next ) {
console.log( "world" );
next();
} );
express.listen( 8888 );
澄清:
以下代码在控制台上显示“之前”,但不显示“之后”:
var express = require( "express" )();
express.use( function( req, res, next ) {
console.log( "before" );
next();
} );
express.get( "/", function( req, res ) {
res.send( "hello" );
} );
express.use( function( req, res, next ) {
console.log( "after" );
next();
} );
express.listen( 8888 );