在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:koajs/path-match开源软件地址:https://github.com/koajs/path-match开源编程语言:JavaScript 100.0%开源软件介绍:Koa Path MatchA simple routing wrapper around path-match. Similar to koa-route, except it optionally handles methods better. All of these routers use path-to-regexp underneath, which is what Express uses as well. const route = require('koa-path-match')({/* options passed to path-to-regexp */})
app.use(route('/:id(\\d+)', (ctx, next) => {
const id = ctx.params.id
// do stuff
switch (ctx.request.method) {
}
})) Or you can create middleware per method: app.use(route('/:id(\\d+)')
.get(async ctx => {
ctx.body = await Things.getById(ctx.params.id)
})
.delete(async ctx => {
await Things.delete(ctx.params.id)
ctx.status = 204
})
) Maintainer
APIroute(path, fns...)
const router = route(path)When you don't set router[method](fns...)Define a middleware just for a specific method. app.use(route('/:id(\\d+)').get(async ctx => {
ctx.body = await Things.getById(ctx.params.id)
}))
this.paramsAny keys defined in the path will be set to |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论