Configure production to run in https

This commit is contained in:
terakilobyte
2015-06-16 14:30:16 -04:00
parent 72770b5fbe
commit 0a8356e50f
4 changed files with 73 additions and 37 deletions

View File

@ -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,6 +297,23 @@ if (process.env.NODE_ENV === 'development') {
* Start Express server.
*/
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(
@ -304,6 +323,7 @@ app.start = function() {
);
});
};
}
// start the server if `$ node server.js`
if (require.main === module) {

16
server/ssl-config.js Normal file
View 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();
}

View File

@ -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')

View File

@ -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')