@@ -23,6 +23,7 @@ const passport = require('passport');
2323const mongoose = require ( 'mongoose' ) ;
2424const compression = require ( 'compression' ) ;
2525const https = require ( 'https' ) ;
26+ const http = require ( 'http' ) ;
2627const fs = require ( 'fs' ) ;
2728const cors = require ( 'cors' ) ;
2829const path = require ( 'path' ) ;
@@ -54,7 +55,6 @@ mongoose
5455
5556app . use ( cors ( ) ) ;
5657
57- app . use ( requireHTTPS ) ;
5858
5959
6060// Express body parser
@@ -82,14 +82,33 @@ const tokensCleanUp = new CronJob('10 3 * * *', function() {
8282tokensCleanUp . start ( ) ;
8383
8484const PORT = process . env . PORT ;
85- https . createServer ( {
86- key : fs . readFileSync ( process . env . SSLKEY ) ,
87- cert : fs . readFileSync ( process . env . SSLCERT ) ,
85+
86+
87+ http . createServer ( {
8888} , app )
8989 . listen ( PORT , function ( ) {
90- console . log ( 'App listening on port ' + PORT + '! Go to https ://localhost:' + PORT + '/' ) ;
90+ console . log ( 'App listening on port ' + PORT + '! Go to http ://localhost:' + PORT + '/' ) ;
9191 } ) ;
9292
93+
94+
95+ // FOR HTTPS ONLY
96+ // https.createServer({
97+ // key: fs.readFileSync(process.env.SSLKEY),
98+ // cert: fs.readFileSync(process.env.SSLCERT),
99+ // }, app)
100+ // .listen(PORT, function() {
101+ // console.log('App listening on port ' + PORT + '! Go to https://localhost:' + PORT + '/');
102+ // });
103+ // app.use(requireHTTPS); FOR HTTPS
104+ // app.enable('trust proxy');
105+ // app.use(function(req, res, next) {
106+ // if (req.secure) {
107+ // return next();
108+ // }
109+ // res.redirect('https://' + req.headers.host + req.url);
110+ // });
111+
93112/**
94113 * @param {int } req req.
95114 * @param {int } res res.
@@ -101,12 +120,4 @@ function requireHTTPS(req, res, next) {
101120 return res . redirect ( 'https://' + req . get ( 'host' ) + req . url ) ;
102121 }
103122 next ( ) ;
104- }
105-
106- app . enable ( 'trust proxy' ) ;
107- app . use ( function ( req , res , next ) {
108- if ( req . secure ) {
109- return next ( ) ;
110- }
111- res . redirect ( 'https://' + req . headers . host + req . url ) ;
112- } ) ;
123+ }
0 commit comments