From e0a7231494891ff53421c6489a9bd981d022009c Mon Sep 17 00:00:00 2001 From: virus Date: Fri, 2 Jul 2021 12:57:48 +0200 Subject: [PATCH] Initial commit --- Dockerfile | 12 ++++++++++++ app.js | 41 +++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 26 ++++++++++++++++++++++++++ public/.index.html.swp | Bin 0 -> 12288 bytes public/index.html | 13 +++++++++++++ public/test.php | 15 +++++++++++++++ 6 files changed, 107 insertions(+) create mode 100644 Dockerfile create mode 100644 app.js create mode 100644 docker-compose.yml create mode 100644 public/.index.html.swp create mode 100644 public/index.html create mode 100644 public/test.php diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5958d30 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM node:14-alpine + +RUN npm install --silent socket.io + +RUN npm install --silent express + +RUN mkdir /srv/public/ + +COPY ./app.js /srv/app.js +COPY ./public/index.html /srv/public/index.html + +CMD node /srv/app.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..b153647 --- /dev/null +++ b/app.js @@ -0,0 +1,41 @@ +const PORT = process.env.PORT || 8080; +const PREFIX = process.env.PREFIX || '/ws'; +console.log('Socket.io listen on: http://localhost:' + PORT + '' + PREFIX + '/socket.io'); +console.log('Publisher listen on: http://localhost:' + PORT + '' + PREFIX + '/pub/$roomID'); + +const app = require('express')(); +const server = require('http').createServer(app); +const io = require('socket.io')(server, {path: PREFIX + '/socket.io'}); +const bodyParser = require('body-parser'); + + +var jsonParser = bodyParser.json(); + +app.get('/test', function (req, res) { + //res.send('') + res.sendFile(__dirname + '/public/index.html') +}); + +app.post('/pub/:roomId', jsonParser, function (req,res) { + console.log('publish to ' + req.params.roomId + ' data:'); + console.log(req.body); + io.to(req.params.roomId).emit('data',req.body); + res.sendStatus(200); +}); + + +io.on('connection', function(socket) { + console.log('new user ' + socket.id); + if (typeof socket.handshake.query.id !== 'undefined') { + const room = socket.handshake.query.id; + socket.join(room); + console.log('user ' + socket.id + ' joined to room ' + room); + } + socket.on('disconnect', () => { + console.log('user ' + socket.id + ' disconnected'); + }); +}); + + + +server.listen(PORT); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..59e083d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3' +services: + push: + image: registry.docker.tlfactory.pl/apps/push-stream-channels:0.1 + build: + context: . + dockerfile: ./Dockerfile + restart: on-failure + environment: + - PORT=8080 + ports: + - 80:8080 + volumes: + - ./app.js:/srv/app.js + - ./public:/srv/public + networks: + - backend + php: + image: registry.docker.tlfactory.pl/apps/php-apache:7.4.20 + networks: + - backend + volumes: + - ./public/:/var/www/html + +networks: + backend: diff --git a/public/.index.html.swp b/public/.index.html.swp new file mode 100644 index 0000000000000000000000000000000000000000..e8710760028c668fc00abbc1c0cd01fb8624e744 GIT binary patch literal 12288 zcmeI&J5Iwe90qU$6G%J+3v4DJrHB$kSx{-SGcdvmCb6188VB3uA%wUE=Ro2H>|6nH z3TFO^QdKYjBcRXfS0{ePzb$G{HV^mq`A*PcROaaO`f}WSTV?Hsd1kbBW%GB%=}Tn> zwp!w=v7)cyREomrQ+4L9MXaMUWkfNs$%b`C$^J%^$UIk>rN)yijYOKq>MBTFKl^H7 z^g#duKMVoZ zW1s5!78L{_009U<00Izz00bZa0SG_<0)J3I#*97AFg7tu4^O}U58wZv>HdjwPr0G= zC`Xi#vQAl{EKwFIQZI?|(I=4DgL8f~RX?oODcG>b@>@LuG!;httev?<7yc_bHYCt)+ z9C$uZ=DN*&+GDG=?N@DubO|+yODpPiQtdaZu5ve5ug<$X)eSFku4oI9=}2aYw$5wP b7M=PzIUinfYof0AVa?I%!KwAa(c#_!ZRU9= literal 0 HcmV?d00001 diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..d357113 --- /dev/null +++ b/public/index.html @@ -0,0 +1,13 @@ + + + +
+
diff --git a/public/test.php b/public/test.php new file mode 100644 index 0000000..f6247bb --- /dev/null +++ b/public/test.php @@ -0,0 +1,15 @@ + $data ) ); +curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); +curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); +# Return response instead of printing. +curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); +# Send request. +$result = curl_exec($ch); +var_export($result); +curl_close($ch); +# Print response. +echo "
$result
";