Configure production to run in https
This commit is contained in:
@ -2,7 +2,9 @@ require('dotenv').load();
|
||||
require('pmx').init();
|
||||
// handle uncaught exceptions. Forever will restart process on shutdown
|
||||
|
||||
var R = require('ramda'),
|
||||
var https = require('https'),
|
||||
sslConfig = require('./ssl-config'),
|
||||
R = require('ramda'),
|
||||
assign = require('lodash').assign,
|
||||
loopback = require('loopback'),
|
||||
boot = require('loopback-boot'),
|
||||
@ -295,7 +297,24 @@ if (process.env.NODE_ENV === 'development') {
|
||||
* Start Express server.
|
||||
*/
|
||||
|
||||
app.start = function() {
|
||||
var options = {
|
||||
key: sslConfig.privateKey,
|
||||
cert: sslConfig.certificate
|
||||
};
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
app.start = function() {
|
||||
var server = https.createServer(options, app);
|
||||
server.listen('https://' + process.env.HOST + ':' + app.get('port'), function () {
|
||||
console.log(
|
||||
'FreeCodeCamp server listening on port %d in %s mode',
|
||||
app.get('port'),
|
||||
app.get('env')
|
||||
);
|
||||
});
|
||||
};
|
||||
} else {
|
||||
app.start = function () {
|
||||
app.listen(app.get('port'), function () {
|
||||
console.log(
|
||||
'FreeCodeCamp server listening on port %d in %s mode',
|
||||
@ -303,7 +322,8 @@ app.start = function() {
|
||||
app.get('env')
|
||||
);
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// start the server if `$ node server.js`
|
||||
if (require.main === module) {
|
||||
|
16
server/ssl-config.js
Normal file
16
server/ssl-config.js
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Created by nathanleniz on 6/16/15.
|
||||
*/
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
exports.privateKey =
|
||||
fs.readFileSync(path.join(__dirname,
|
||||
'../../private/privatekey.pem')).toString();
|
||||
exports.certificate =
|
||||
fs.readFileSync(path.join(__dirname,
|
||||
'../../private/certificate.pem')).toString();
|
||||
|
||||
}
|
@ -11,7 +11,7 @@ block content
|
||||
link(rel='stylesheet', href='/js/lib/codemirror/lib/codemirror.css')
|
||||
link(rel='stylesheet', href='/js/lib/codemirror/addon/lint/lint.css')
|
||||
link(rel='stylesheet', href='/js/lib/codemirror/theme/monokai.css')
|
||||
link(rel="stylesheet", href="http://fonts.googleapis.com/css?family=Ubuntu+Mono")
|
||||
link(rel="stylesheet", href="//fonts.googleapis.com/css?family=Ubuntu+Mono")
|
||||
script(type='text/javascript', src='/js/lib/codemirror/mode/javascript/javascript.js')
|
||||
script(type='text/javascript', src='/js/lib/jailed/jailed.js')
|
||||
script(type='text/javascript', src='/js/lib/coursewares/sandbox.js')
|
||||
|
@ -10,7 +10,7 @@ block content
|
||||
link(rel='stylesheet', href='/js/lib/codemirror/lib/codemirror.css')
|
||||
link(rel='stylesheet', href='/js/lib/codemirror/addon/lint/lint.css')
|
||||
link(rel='stylesheet', href='/js/lib/codemirror/theme/monokai.css')
|
||||
link(rel="stylesheet", href="http://fonts.googleapis.com/css?family=Ubuntu+Mono")
|
||||
link(rel="stylesheet", href="//fonts.googleapis.com/css?family=Ubuntu+Mono")
|
||||
script(src='/js/lib/codemirror/mode/javascript/javascript.js')
|
||||
script(src='/js/lib/jailed/jailed.js')
|
||||
script(src='/js/lib/coursewares/sandbox.js')
|
||||
|
Reference in New Issue
Block a user