我想添加一个必须在发生请求时触发的Express中间件POST(与路由 URL 无关)。
我认为这样的事情应该有效:
app.use(function (req, res, next) {
if (req.method === 'POST') {
console.log('Time:', Date.now());
}
});
Run Code Online (Sandbox Code Playgroud)
但我想知道Express是否有开箱即用的功能来处理这些场景。
是的。
app.post(function (req, res, next) {
Run Code Online (Sandbox Code Playgroud)
http://expressjs.com/api.html#router.METHOD
| 归档时间: |
|
| 查看次数: |
1440 次 |
| 最近记录: |