UNPKG

koa-enforces-ssl

Version:
17 lines (15 loc) 346 B
module.exports = (ctx, next) => { if (ctx.secure) { return next() } else { redirect(ctx) } } const redirect = (ctx) => { if (ctx.method === 'GET') { ctx.status = 301 ctx.redirect(`https://${ctx.headers.host}${ctx.originalUrl}`) } else { ctx.throw(403, 'Please use HTTPS when submitting data to this server.') } }