add redirect for https
This commit is contained in:
35
server/boot/redirectHttps.js
Normal file
35
server/boot/redirectHttps.js
Normal file
@ -0,0 +1,35 @@
|
||||
var path = require('path');
|
||||
var loopback = require('loopback');
|
||||
var express = require('express');
|
||||
|
||||
var port = 1337;
|
||||
|
||||
// this will listen to traffic on port 1337
|
||||
// The purpose is to redirect any user who is direct to https
|
||||
// instead of http by mistake. Our nginx proxy server will listen
|
||||
// for https traffic and serve from this port on this server.
|
||||
// the view being send will have a short timeout and a redirect
|
||||
module.exports = function(loopbackApp) {
|
||||
var app = express();
|
||||
app.set('view engine', 'jade');
|
||||
// views in ../views'
|
||||
app.set('views', path.join(__dirname, '..'));
|
||||
|
||||
// server static files
|
||||
app.use(loopback.static(path.join(
|
||||
__dirname,
|
||||
'../',
|
||||
'../public'
|
||||
)));
|
||||
|
||||
// all traffic will be redirected on page load;
|
||||
app.use(function(req, res) {
|
||||
return res.render('views/redirect-https');
|
||||
});
|
||||
|
||||
loopbackApp.once('started', function() {
|
||||
app.listen(port, function() {
|
||||
console.log('https redirect lisenting on port %s', port);
|
||||
});
|
||||
});
|
||||
};
|
@ -303,6 +303,7 @@ module.exports = app;
|
||||
|
||||
app.start = function () {
|
||||
app.listen(app.get('port'), function() {
|
||||
app.emit('started');
|
||||
console.log(
|
||||
'FreeCodeCamp server listening on port %d in %s mode',
|
||||
app.get('port'),
|
||||
|
21
server/views/partials/small-head.jade
Normal file
21
server/views/partials/small-head.jade
Normal file
@ -0,0 +1,21 @@
|
||||
script(src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js")
|
||||
script(src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js")
|
||||
link(rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Lato:400|Inconsolata")
|
||||
link(rel='stylesheet', href='/bower_components/font-awesome/css/font-awesome.min.css')
|
||||
link(rel='stylesheet', href='/css/main.css')
|
||||
// End **REQUIRED** includes
|
||||
|
||||
include meta
|
||||
title redirecting to | Free Code Camp
|
||||
meta(charset='utf-8')
|
||||
meta(http-equiv='X-UA-Compatible', content='IE=edge')
|
||||
meta(name='viewport', content='width=device-width, initial-scale=1.0')
|
||||
meta(name='csrf-token', content=_csrf)
|
||||
script.
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
ga('create', 'UA-55446531-1', 'auto');
|
||||
ga('require', 'displayfeatures');
|
||||
ga('send', 'pageview');
|
15
server/views/redirect-https.jade
Normal file
15
server/views/redirect-https.jade
Normal file
@ -0,0 +1,15 @@
|
||||
doctype html
|
||||
html(lang='en')
|
||||
head
|
||||
include partials/small-head
|
||||
body.top-and-bottom-margins
|
||||
include partials/navbar
|
||||
.container
|
||||
.row
|
||||
.panel.panel-info
|
||||
p redirecting you... please wait...
|
||||
include partials/footer
|
||||
script.
|
||||
setTimeout(function() {
|
||||
window.location = 'http://freecodecamp.com'
|
||||
}, 500);
|
Reference in New Issue
Block a user