Created
July 13, 2015 18:42
-
-
Save jasco/4f27de43cb187eb34653 to your computer and use it in GitHub Desktop.
TLS enabled deployd (https/ssl/tls)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var https = require('https'); | |
var deployd = require('deployd'); | |
var express = require('express'); | |
var socketIO = require('socket.io'); | |
var dbhost = process.env.MONGODB_TCP_ADDR; | |
var dbport = process.env.MONGODB_TCP_PORT; | |
var dbname = process.env.MONGODB_DB_NAME || 'dbname'; | |
var dbuser = process.env.MONGODB_USERNAME; | |
var dbpwd = process.env.MONGODB_PASSWORD; | |
var port = process.env.DEPLOYD_PORT || 443; | |
var env = process.env.ENV || 'production'; | |
// Test TLS security and adjust ciphers if needed | |
var securityOptions = { | |
key: fs.readFileSync('/certs/private/ssl-cert.key'), | |
cert: fs.readFileSync('/certs/ssl-cert.pem'), | |
ca: fs.readFileSync('/certs/ssl-cert-intermediate.pem'), | |
ciphers: 'ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL', | |
honorCipherOrder: true | |
}; | |
var app = express(); | |
var secureServer = https.createServer(securityOptions, app); | |
var io = socketIO.listen(secureServer); | |
var deploydOpt = { | |
socketIo: io, | |
env: env, | |
db: { | |
host:dbhost, | |
port:dbport, | |
name:dbname | |
} | |
}; | |
if (dbuser && dbpwd) { | |
deploydOpt.credentials = { | |
username: dbuser, | |
password: dbpwd | |
}; | |
} | |
secureServer.on('listening', function() { | |
console.log("Server is listening on port " + port); | |
}); | |
secureServer.on('error', function(err) { | |
console.error(err); | |
process.nextTick(function() { // Give the server a chance to return an error | |
process.exit(); | |
}); | |
}); | |
deployd.attach(secureServer, deploydOpt); | |
app.use(secureServer.handleRequest); | |
secureServer.listen(port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment