Skip to content

Commit

Permalink
listen on unique host for https
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Sep 7, 2014
1 parent 70620a8 commit ca5cbfb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
9 changes: 9 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var PORT_80 = process.env.NODE_ENV === 'production' ? 80 : 9100
var PORT_443 = process.env.NODE_ENV === 'production' ? 80 : 9101

exports.host = process.env.NODE_ENV === 'production' && '23.239.22.146'

exports.ports = {
http: PORT_80,
https: PORT_443
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"jade": "^1.5.0",
"parse-torrent": "^2.1.0",
"posix": "^1.0.3",
"run-parallel": "^1.0.0",
"stylus": "^0.47.3"
},
"devDependencies": {
Expand Down
23 changes: 11 additions & 12 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
var compress = require('compression')
var config = require('../config')
var debug = require('debug')('webtorrent:web')
var express = require('express')
var fs = require('fs')
var http = require('http')
var https = require('https')
var jade = require('jade')
var parallel = require('run-parallel')
var path = require('path')
var url = require('url')
var util = require('./util')

var HTTP_PORT = process.argv[2] || 9100
var HTTPS_PORT = process.argv[3] ||
(process.env.NODE_ENV === 'production') ? 443 : 9101

var app = express()
var httpServer = http.createServer(app)
var httpsServer = https.createServer({
Expand Down Expand Up @@ -64,14 +62,15 @@ app.get('*', function (req, res) {
res.render('error')
})

httpServer.listen(HTTP_PORT, function (err) {
if (err) throw err
debug('http listening on port ' + HTTP_PORT)
util.downgradeUid()
})

httpsServer.listen(HTTPS_PORT, function (err) {
parallel([
function (cb) {
httpServer.listen(config.ports.http, config.host, cb)
},
function (cb) {
httpsServer.listen(config.ports.https, config.host, cb)
}
], function (err) {
if (err) throw err
debug('https listening on port ' + HTTPS_PORT)
debug('listening on port %s', JSON.stringify(config.ports))
util.downgradeUid()
})

0 comments on commit ca5cbfb

Please sign in to comment.