Skip to content

Allow HOST to be set for listening binding #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
FROM node:4-onbuild
ARG DOMAIN=runfullstack.co

COPY ./config /usr/src/app
ENV NODE_ENV production

RUN sed -i -e "s/config\/sslcerts\/key.pem/\/etc\/letsencrypt\/live\/$DOMAIN\/privkey.pem/g" /usr/src/app/config/production.json && \
sed -i -e "s/config\/sslcerts\/cert.pem/\/etc\/letsencrypt\/live\/$DOMAIN\/cert.pem/g" /usr/src/app/config/production.json

RUN apt-get update -yq && \
apt-get install -yq supervisor && \
mkdir -p /var/log/supervisor

COPY ./supervisord.conf /etc/supervisor/conf.d/signalmaster.conf

CMD ["/usr/bin/supervisord"]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ To run the image execute this:
docker run --name signalmaster -d -p 8888:8888 signalmaster

This will start a signal master server on port 8888 exposed on port 8888.

## Differences

This version allows you to set the host for listening.

docker build -t signalmaster .

Run the image:

docker run -d -p 8080:8080 -e PORT=8080 -e HOST=0.0.0.0 -e NODE_ENV=production auser/signalmaster
1 change: 1 addition & 0 deletions config/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"isDev": true,
"server": {
"port": 8888,
"host": "0.0.0.0",
"/* secure */": "/* whether this connects via https */",
"secure": false,
"key": null,
Expand Down
1 change: 1 addition & 0 deletions config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"isDev": false,
"server": {
"port": 8888,
"host": "0.0.0.0",
"/* secure */": "/* whether this connects via https */",
"secure": true,
"key": "config/sslcerts/key.pem",
Expand Down
18 changes: 16 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var yetify = require('yetify'),
fs = require('fs'),
sockets = require('./sockets'),
port = parseInt(process.env.PORT || config.server.port, 10),
host = process.env.HOST || config.server.host,
le_domain = process.env.DOMAIN || false,
server_handler = function (req, res) {
res.writeHead(404);
res.end();
Expand All @@ -12,6 +14,18 @@ var yetify = require('yetify'),

// Create an http(s) server instance to that socket.io can listen to
if (config.server.secure) {
var fileExists = function (fp) {
try { fs.accessSync(fp); return true } catch (err) { return false; }
}
if (le_domain) {
var le_path = "/etc/letsencrypt/live/" + le_domain + "/";
if (fileExists(le_path + "privkey.pem")) {
config.server.key = le_path + "privkey.pem"
}
if (fileExists((le_path + "cert.pem"))) {
config.server.cert = le_path + "cert.pem"
}
}
server = require('https').Server({
key: fs.readFileSync(config.server.key),
cert: fs.readFileSync(config.server.cert),
Expand All @@ -28,8 +42,8 @@ if (config.uid) process.setuid(config.uid);

var httpUrl;
if (config.server.secure) {
httpUrl = "https://localhost:" + port;
httpUrl = "https://" + host + ":" + port;
} else {
httpUrl = "http://localhost:" + port;
httpUrl = "http://" + host + ":" + port;
}
console.log(yetify.logo() + ' -- signal master is running at: ' + httpUrl);
11 changes: 11 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[supervisord]
nodaemon=true

[program:signalmaster]
command = /usr/local/bin/node /usr/src/app/server.js
directory = /usr/src/app
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/signalmaster.log
stderr_logfile = /var/log/supervisor/signalmaster_err.log
environment = NODE_ENV="production"