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
- Host: GitHub
- URL: https://github.com/dotcypress/koa-force-ssl
- Owner: dotcypress
- License: mit
- Created: 2014-05-21T16:03:29.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2018-08-28T21:45:32.000Z (over 6 years ago)
- Last Synced: 2025-03-18T09:03:20.211Z (about 2 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 31
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-force-ssl
[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