Skip to content

Commit

Permalink
update server_example Dockerfile and server_ssl example
Browse files Browse the repository at this point in the history
  • Loading branch information
hthetiot committed Nov 26, 2018
1 parent 34e422b commit 94a923d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 11 deletions.
5 changes: 4 additions & 1 deletion server_example/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ MAINTAINER Harold Thetiot <[email protected]>

# Upgrade npm
RUN npm i npm@latest -g
ENV NO_UPDATE_NOTIFIER 1

# Create app directory
ENV APPDIR /usr/src/app
Expand All @@ -23,9 +24,11 @@ RUN npm install --production

ADD . $APPDIR

VOLUME ['certs', 'static']

# Replace 'easyrtc = require("..");' by 'easyrtc = require("easyrtc");''
# To use easyrtc from node_modules instead of parent directory
RUN sed -i "s|easyrtc = require(\"../\")|easyrtc = require(\"easyrtc\")|g" $APPDIR/server*.js
RUN sed -i "s|easyrtc = require(\"../\")|easyrtc = require(\"easyrtc\")|g" $APPDIR/*.js

# Define service user
RUN chown -R nobody:nogroup $APPDIR && chmod -R a-w $APPDIR && ls -ld
Expand Down
22 changes: 22 additions & 0 deletions server_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,25 @@ Running the Server using docker-compose:
- Type `npm run docker-compose:start` in console.

Note: Require docker-compose to be installed.


Manualy build and run container
-------------------

Build:
> docker build . -t easyrtc
Run default:
> docker run -it --name easyrtc -p 8080:8080 easyrtc
Run HTTP server:
> docker run -it --name easyrtc --rm -p 8080:8080 easyrtc run server
Run HTTPS server:
> docker run -it --name easyrtc --rm -p 8443:8443 easyrtc run server_ssl
Run HTTPS server with custom certs:
> docker run -it --name easyrtc --rm -p 8443:8443 -v $(pwd)/certs/:/usr/src/app/certs/:ro easyrtc run server_ssl


File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion server_example/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ services:
build:
context: .
args:
EASYRTC_BRANCH: "feature/docker-easyrtc-server"
EASYRTC_BRANCH: "master"
command: server_ssl
volume:
- ./certs:/usr/src/app/certs:ro
networks:
- frontend
ports:
Expand Down
4 changes: 3 additions & 1 deletion server_example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"description": "Simple EasyRTC server example which includes EasyRTC, Express, and Socket.io",
"private": true,
"scripts": {
"start": "node server.js",
"start": "npm run server",
"server": "node server.js",
"server_ssl": "node server_ssl.js",
"docker:build": "docker build -t easyrtc-server -f Dockerfile .",
"docker:start": "docker run -it -d -p 8080:8080 easyrtc-server",
"docker:start": "docker easyrtc-server",
Expand Down
2 changes: 1 addition & 1 deletion server_example/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var rtc = easyrtc.listen(app, socketServer, null, function(err, rtcRef) {
});
});

//listen on port 8080
// Listen on port 8080
webServer.listen(8080, function () {
console.log('listening on http://localhost:8080');
});
18 changes: 11 additions & 7 deletions server_example/server_ssl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@ var io = require("socket.io"); // web socket external module
// To use this server_example folder only without parent folder:
// 1. you need to replace this "require("../");" by "require("easyrtc");"
// 2. install easyrtc (npm i easyrtc --save) in server_example/package.json
var easyrtc = require(".."); // EasyRTC internal module

var easyrtc = require("../"); // EasyRTC internal module

// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
var httpApp = express();
httpApp.use(express.static(__dirname + "/static/"));

// Start Express https server on port 8443
var webServer = https.createServer(
{
key: fs.readFileSync("localhost.key"),
cert: fs.readFileSync("localhost.crt")
},
httpApp).listen(8443);
var webServer = https.createServer({
key: fs.readFileSync(__dirname + "/certs/localhost.key"),
cert: fs.readFileSync(__dirname + "/certs/localhost.crt")
}, httpApp);

// Start Socket.io so it attaches itself to Express server
var socketServer = io.listen(webServer, {"log level":1});

// Start EasyRTC server
var rtc = easyrtc.listen(httpApp, socketServer);

// Listen on port 8443
webServer.listen(8443, function () {
console.log('listening on https://localhost:8443');
});

0 comments on commit 94a923d

Please sign in to comment.