koa - Koajs: How to check current connection is over https or not? -
i using koajs, have router following , want detect if user requesting via https, how can achieve it?
router.get('/video', function(next){ if(request on https) { this.body = yield render('/video', {}); } else { this.redirect('https://example.com/video'); } });
you can use secure
attached context's request
object. it's aliased onto ctx
itself.
koa v1:
router.get('/video', function *(next) { if (this.secure) { // request on https } })
koa v2:
router.get('/video', async (ctx, next) => { if (ctx.secure) { // request on https } })
ctx.secure
equivalent checking ctx.protocol === "https"
.
this mentioned in koa website docs, recommend checking there first whenever have koa-related question.
Comments
Post a Comment