An open API service indexing awesome lists of open source software.

https://github.com/dotcypress/koa-force-ssl

Koa.js middleware for force SSL
https://github.com/dotcypress/koa-force-ssl

Last synced: about 2 months ago
JSON representation

Koa.js middleware for force SSL

Awesome Lists containing this project

README

        

# koa-force-ssl

![KoaJs Slack](https://img.shields.io/badge/Koa.Js-Slack%20Channel-Slack.svg?longCache=true&style=for-the-badge)

[Koa.js](http://koajs.com/) middleware for force SSL

*This middleware is deprecated, please use [koa-sslify](https://github.com/turboMaCk/koa-sslify)*

## Install
```
$ npm install koa-force-ssl
```

## API
`forceSSL(port, hostname, temporary);`

* port - SSL port (default value: 443)
* hostname - host name for redirect (by default will redirect to same host)
* temporary - use "302 Temporary Redirect" (by default will use "301 Permanent Redirect")

## Example
```
var koa = require('koa');
var http = require('http');
var https = require('https');
var fs = require('fs');
var forceSSL = require('koa-force-ssl');

var app = koa();

// Force SSL on all page
app.use(forceSSL());

// index page
app.use(function * (next) {
this.body = "hello world from " + this.request.url;
});

// SSL options
var options = {
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt')
}

// start the server
http.createServer(app.callback()).listen(80);
https.createServer(options, app.callback()).listen(443);
```

## License
MIT