Express4中文文档
返回单个路由的实例,然后您可以使用它来处理带有可选中间件的 HTTP 动词。使用 app.route()
来避免重复的路由名称(从而避免拼写错误)。
var app = express()
app.route('/events')
.all(function (req, res, next) {
// runs for all HTTP verbs first
// think of it as route specific middleware!
})
.get(function (req, res, next) {
res.json({})
})
.post(function (req, res, next) {
// maybe add a new event...
})