Redirecting http to https
Signed-off-by: Walamana <joniogerg@gmail.com>
This commit is contained in:
34
node_modules/express-force-ssl/examples/example.js
generated
vendored
Normal file
34
node_modules/express-force-ssl/examples/example.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
var express = require('express')
|
||||
, forceSSL = require('./../index')
|
||||
, fs = require('fs')
|
||||
, http = require('http')
|
||||
, https = require('https')
|
||||
;
|
||||
|
||||
var ssl_options = {
|
||||
key: fs.readFileSync('./test/keys/localhost.key'),
|
||||
cert: fs.readFileSync('./test/keys/localhost.crt'),
|
||||
ca: fs.readFileSync('./test/keys/localhost.crt')
|
||||
};
|
||||
|
||||
var app = express();
|
||||
var server = http.createServer(app);
|
||||
var secureServer = https.createServer(ssl_options, app);
|
||||
|
||||
app.get('/', function(req, res){
|
||||
res.json({msg: 'accessible by http'});
|
||||
});
|
||||
app.get('/ssl', forceSSL, function(req, res){
|
||||
res.json({msg: 'only https'});
|
||||
});
|
||||
|
||||
app.get('/ssl/deep/route/:id', forceSSL, function(req, res){
|
||||
var host = req.headers.host.split(':');
|
||||
var port = host.length > 1 ? host[1] : 'default port';
|
||||
res.json({msg: 'only https, port: ' + port, id: req.param('id')});
|
||||
});
|
||||
|
||||
app.set('httpsPort', 8443);
|
||||
|
||||
secureServer.listen(8443);
|
||||
server.listen(8080);
|
||||
Reference in New Issue
Block a user