koa2-ssl
v1.2.0
Published
Enforce SSL for koa apps
Downloads
15
Readme
koa2-ssl
koa2-ssl enforces SSL for Koa 2 apps.
Use
Simply require and use the function exported by this module:
const ssl = require('koa2-ssl');
const app = require('koa')();
const handleDisallow = ctx => {
ctx.status = 403;
ctx.body = 'HTTPS access only.';
};
const opts = {
disable: false,
trustProxy: false,
disallow: handleDisallow,
};
app.use(ssl(opts));
The function takes an optional object of options:
|Option|Type|Default value|Description|
|:-----|:---|:------------|:----------|
|disabled|boolean
|false
|If true
, this middleware will allow all requests through.|
|trustProxy|boolean
|false
|If true
, trust the x-forwarded-proto
header. If it is "https", requests are allowed through.|
|disallow|(ctx: Context) => any
|undefined
|A function called with the Koa context so that the user can handle rejecting non-SSL requests themselves.|
By default, this middleware will only run when process.env.NODE_ENV
is set to
"production". Unless a disallow
function is supplied it will respond with the
status code 403 and the body "Please use HTTPS when communicating with this
server."