# koa2-ssl

> Enforce SSL for koa apps

Latest version **1.2.0** (published 2021-12-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa2-ssl
pnpm add koa2-ssl
yarn add koa2-ssl
bun add koa2-ssl
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2021-12-14 |
| First published | 2018-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 13.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Antoine Lépée |
| Maintainers | alepee |
| Keywords | ssl, koa2, middleware |

## Links

- npm: https://www.npmjs.com/package/koa2-ssl
- Repository: https://github.com/alepee/koa2-ssl
- Issues: https://github.com/alepee/koa2-ssl/issues
- npm.io page: https://npm.io/package/koa2-ssl

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2021-12-14
- 1.1.1 — 2020-09-24
- 1.1.0 — 2020-02-19
- 1.0.5 — 2019-07-17
- 1.0.4 — 2018-12-14
- 1.0.3 — 2018-12-06
- 1.0.2 — 2018-12-04
- 1.0.1 — 2018-05-29
- 1.0.0 — 2018-02-22

## README

# koa2-ssl

![Test](https://github.com/alepee/koa2-ssl/actions/workflows/npm-test.yml/badge.svg)
![CodeQL](https://github.com/alepee/koa2-ssl/actions/workflows/codeql-analysis.yml/badge.svg)

koa2-ssl enforces SSL for [Koa 2][koa] apps.

## Use

Simply require and use the function exported by this module:

```javascript
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."

[koa]: https://github.com/koajs/koa

## Credits

This package is an update of [jclem](https://github.com/jclem)'s [koa-ssl](https://github.com/jclem/koa-ssl) for koa@^2.1

---
_Source: https://npm.io/package/koa2-ssl · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
