Remove ssl on node servers
This commit is contained in:
@ -2,9 +2,7 @@ require('dotenv').load();
|
|||||||
require('pmx').init();
|
require('pmx').init();
|
||||||
// handle uncaught exceptions. Forever will restart process on shutdown
|
// handle uncaught exceptions. Forever will restart process on shutdown
|
||||||
|
|
||||||
var https = require('https'),
|
var R = require('ramda'),
|
||||||
sslConfig = require('./ssl-config'),
|
|
||||||
R = require('ramda'),
|
|
||||||
assign = require('lodash').assign,
|
assign = require('lodash').assign,
|
||||||
loopback = require('loopback'),
|
loopback = require('loopback'),
|
||||||
boot = require('loopback-boot'),
|
boot = require('loopback-boot'),
|
||||||
@ -54,10 +52,12 @@ app.use(compress());
|
|||||||
app.use(lessMiddleware(path.join(__dirname, '/public')));
|
app.use(lessMiddleware(path.join(__dirname, '/public')));
|
||||||
app.use(logger('dev'));
|
app.use(logger('dev'));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(bodyParser.urlencoded({ extended: true }));
|
app.use(bodyParser.urlencoded({
|
||||||
|
extended: true
|
||||||
|
}));
|
||||||
app.use(expressValidator({
|
app.use(expressValidator({
|
||||||
customValidators: {
|
customValidators: {
|
||||||
matchRegex: function (param, regex) {
|
matchRegex: function(param, regex) {
|
||||||
return regex.test(param);
|
return regex.test(param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,8 +145,7 @@ app.use(helmet.csp({
|
|||||||
'https://cdn.inspectlet.com/inspectlet.js',
|
'https://cdn.inspectlet.com/inspectlet.js',
|
||||||
'http://cdn.inspectlet.com/inspectlet.js'
|
'http://cdn.inspectlet.com/inspectlet.js'
|
||||||
].concat(trusted),
|
].concat(trusted),
|
||||||
'connect-src': [
|
'connect-src': [].concat(trusted),
|
||||||
].concat(trusted),
|
|
||||||
styleSrc: [
|
styleSrc: [
|
||||||
'*.googleapis.com',
|
'*.googleapis.com',
|
||||||
'*.gstatic.com'
|
'*.gstatic.com'
|
||||||
@ -180,14 +179,16 @@ app.use(helmet.csp({
|
|||||||
|
|
||||||
passportConfigurator.init();
|
passportConfigurator.init();
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
// Make user object available in templates.
|
// Make user object available in templates.
|
||||||
res.locals.user = req.user;
|
res.locals.user = req.user;
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
loopback.static(path.join(__dirname, '../public'), { maxAge: 86400000 })
|
loopback.static(path.join(__dirname, '../public'), {
|
||||||
|
maxAge: 86400000
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
boot(app, {
|
boot(app, {
|
||||||
@ -195,7 +196,7 @@ boot(app, {
|
|||||||
dev: process.env.NODE_ENV
|
dev: process.env.NODE_ENV
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
// Remember original destination before login.
|
// Remember original destination before login.
|
||||||
var path = req.path.split('/')[1];
|
var path = req.path.split('/')[1];
|
||||||
if (/auth|login|logout|signin|signup|fonts|favicon/i.test(path)) {
|
if (/auth|login|logout|signin|signup|fonts|favicon/i.test(path)) {
|
||||||
@ -224,7 +225,8 @@ var passportOptions = {
|
|||||||
null;
|
null;
|
||||||
|
|
||||||
var username = (profile.username || profile.id);
|
var username = (profile.username || profile.id);
|
||||||
username = typeof username === 'string' ? username.toLowerCase() : username;
|
username = typeof username === 'string' ? username.toLowerCase() :
|
||||||
|
username;
|
||||||
var password = generateKey('password');
|
var password = generateKey('password');
|
||||||
var userObj = {
|
var userObj = {
|
||||||
username: username,
|
username: username,
|
||||||
@ -256,7 +258,9 @@ R.keys(passportProviders).map(function(strategy) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
app.use(errorHandler({ log: true }));
|
app.use(errorHandler({
|
||||||
|
log: true
|
||||||
|
}));
|
||||||
} else {
|
} else {
|
||||||
app.use(pmx.expressErrorHandler());
|
app.use(pmx.expressErrorHandler());
|
||||||
// error handling in production disabling eslint due to express parity rules
|
// error handling in production disabling eslint due to express parity rules
|
||||||
@ -279,12 +283,16 @@ if (process.env.NODE_ENV === 'development') {
|
|||||||
|
|
||||||
var message = 'opps! Something went wrong. Please try again later';
|
var message = 'opps! Something went wrong. Please try again later';
|
||||||
if (type === 'html') {
|
if (type === 'html') {
|
||||||
req.flash('errors', { msg: message });
|
req.flash('errors', {
|
||||||
|
msg: message
|
||||||
|
});
|
||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
// json
|
// json
|
||||||
} else if (type === 'json') {
|
} else if (type === 'json') {
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.setHeader('Content-Type', 'application/json');
|
||||||
return res.send({ message: message });
|
return res.send({
|
||||||
|
message: message
|
||||||
|
});
|
||||||
// plain text
|
// plain text
|
||||||
} else {
|
} else {
|
||||||
res.setHeader('Content-Type', 'text/plain');
|
res.setHeader('Content-Type', 'text/plain');
|
||||||
@ -297,31 +305,14 @@ if (process.env.NODE_ENV === 'development') {
|
|||||||
* Start Express server.
|
* Start Express server.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var options = {
|
|
||||||
key: sslConfig.privateKey,
|
|
||||||
cert: sslConfig.certificate
|
|
||||||
};
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'production') {
|
app.listen(app.get('port'), function() {
|
||||||
var server = https.createServer(options, app);
|
|
||||||
console.log('https://' + process.env.HOST + ':' + process.env.PORT);
|
|
||||||
server.listen(app.get('port'), function () {
|
|
||||||
console.log(
|
console.log(
|
||||||
'FreeCodeCamp server listening on port %d in %s mode',
|
'FreeCodeCamp server listening on port %d in %s mode',
|
||||||
app.get('port'),
|
app.get('port'),
|
||||||
app.get('env')
|
app.get('env')
|
||||||
);
|
);
|
||||||
app.emit('started', 'https://' + process.env.HOST + ':' + app.get('port'));
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
app.listen(app.get('port'), function () {
|
|
||||||
console.log(
|
|
||||||
'FreeCodeCamp server listening on port %d in %s mode',
|
|
||||||
app.get('port'),
|
|
||||||
app.get('env')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// start the server if `$ node server.js`
|
// start the server if `$ node server.js`
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user