ExpressJS App.use路由序列
我在app.js
有以下内容:
app.use(express.static(path.join(__dirname, 'public'))); app.use(function(req, res, next) { console.log('app.use'); ... next(); }); app.use(app.router);
公用文件夹有子文件夹images
, css
和js
。
在app.use(app.router);
,我有从Amazon S3返回图像的路由定义。
app.get('/images/:type/:id', image);
问题是,当一个页面包含图像, app.use
被调用两次。 如何预防呢? 我想忽略/images/*
调用app.use(function(req, res, next) {});
一般Express使用中间件连接体系结构。 每个中间件都接受下一个如果被调用的函数将stream传给下一个中间件。 所以,理论上如果你错过了,你可以存档你想要的东西:
app.use(function(req, res, next) { // check if the route matches amazon file if(...amazon file...) { // serve image } else { next(); } }); app.use(express.static(path.join(__dirname, 'public')));
- 铁路由器:meteorJS
- 使用http-proxy和body-parser与express时,节点挂起POST请求
- 如何使用Mongoose,Express,Angular 4和NodeJS上传/保存和显示图片
- websockets和iOS中的实时更新
- 如何组织由express / koa后端服务的webpacked vue.js应用程序?
- NodeJS + ExpressJS – 无法读取环境variables
- 图片上传失败w / nodejsexpression
- 护照的req.isAuthenticated总是返回false,即使我硬编码完成(null,true)
- 错误:没有指定默认引擎,也没有提供扩展名。 简单的路由