Skip to content

Commit

Permalink
add redirect for https
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Jul 1, 2015
1 parent c434342 commit 580e2e3
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
35 changes: 35 additions & 0 deletions server/boot/redirectHttps.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
};
1 change: 1 addition & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
21 changes: 21 additions & 0 deletions server/views/partials/small-head.jade
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions server/views/redirect-https.jade
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 580e2e3

Please sign in to comment.