1.2.0 • Published 2 years ago

koa2-ssl v1.2.0

Weekly downloads
18
License
MIT
Repository
github
Last release
2 years ago

koa2-ssl

Test CodeQL

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:

OptionTypeDefault valueDescription
disabledbooleanfalseIf true, this middleware will allow all requests through.
trustProxybooleanfalseIf true, trust the x-forwarded-proto header. If it is "https", requests are allowed through.
disallow(ctx: Context) => anyundefinedA 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."

Credits

This package is an update of jclem's koa-ssl for koa@^2.1

1.2.0

2 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago