Socket
Book a DemoInstallSign in
Socket

koa-force-ssl

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-force-ssl

Koa.js middleware for force SSL

latest
Source
npmnpm
Version
0.0.5
Version published
Maintainers
1
Created
Source

#koa-force-ssl

Koa.js middleware for force SSL

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

Keywords

koa

FAQs

Package last updated on 30 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts