来自https://github.com/koajs/jwt
app.use(jwt({ secret: 'shared-secret' }));用于确保后续路由的安全。
问:如果没有匹配的路径,我如何只为定义的一组路由指定它,并将其重定向到静态html页面。
我当前的代码:
app
.use(indexRouter.routes())
.use(jwt({secret: conf.secret }))
.use(protectedRouter.routes())
.use((ctx: any)=> ctx.body='My html page'); <-- this doesn't work because it is considered a protected route预期的伪代码:
app.use(indexRouter.routes())
.use(protectedRouter.routes(), jwt({secret: conf.secret }))
.use((ctx: any)=> ctx.body='My html page'); 发布于 2018-10-30 00:03:23
由于我的受保护路由都在'api‘路由下,所以我这样做:
.use(indexRouter.routes())
.use(async (ctx: Context, next: () => void) => {
if (ctx.path.substring(0,5) === '/api/'){
await next();
}else{
ctx.body='My html page'
}
})
.use(jwt({secret: conf.secret}))
.use(protectedRouter.routes());https://stackoverflow.com/questions/53048938
复制相似问题