about summary refs log tree commit diff
path: root/streaming
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2018-08-26 19:12:07 +0200
committerGitHub <noreply@github.com>2018-08-26 19:12:07 +0200
commitaf934b90710a2ce1099d3ceda5de7bcf0e94595c (patch)
tree71e25690e6300d0235d515ccd0241d082c8d1abe /streaming
parent2903f8f36b7c41b77de4ad6c8c5b0a6c0b2a7ace (diff)
parentbe20eb4b2f4e55c472263a98a2c07b4e805d9bd5 (diff)
Merge pull request #674 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'streaming')
-rw-r--r--streaming/index.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/streaming/index.js b/streaming/index.js
index d7bfa6542..1c6004b77 100644
--- a/streaming/index.js
+++ b/streaming/index.js
@@ -9,6 +9,7 @@ const log = require('npmlog');
 const url = require('url');
 const WebSocket = require('uws');
 const uuid = require('uuid');
+const fs = require('fs');
 
 const env = process.env.NODE_ENV || 'development';
 
@@ -70,6 +71,9 @@ const redisUrlToClient = (defaultConfig, redisUrl) => {
 const numWorkers = +process.env.STREAMING_CLUSTER_NUM || (env === 'development' ? 1 : Math.max(os.cpus().length - 1, 1));
 
 const startMaster = () => {
+  if (!process.env.SOCKET && process.env.PORT && isNaN(+process.env.PORT)) {
+    log.warn('UNIX domain socket is now supported by using SOCKET. Please migrate from PORT hack.');
+  }
   log.info(`Starting streaming API server master with ${numWorkers} workers`);
 };
 
@@ -448,6 +452,12 @@ const startWorker = (workerId) => {
   app.use(setRequestId);
   app.use(setRemoteAddress);
   app.use(allowCrossDomain);
+
+  app.get('/api/v1/streaming/health', (req, res) => {
+    res.writeHead(200, { 'Content-Type': 'text/plain' });
+    res.end('OK');
+  });
+
   app.use(authenticationMiddleware);
   app.use(errorMiddleware);
 
@@ -574,9 +584,16 @@ const startWorker = (workerId) => {
     });
   }, 30000);
 
-  server.listen(process.env.PORT || 4000, process.env.BIND || '0.0.0.0', () => {
-    log.info(`Worker ${workerId} now listening on ${server.address().address}:${server.address().port}`);
-  });
+  if (process.env.SOCKET || process.env.PORT && isNaN(+process.env.PORT)) {
+    server.listen(process.env.SOCKET || process.env.PORT, () => {
+      fs.chmodSync(server.address(), 0o666);
+      log.info(`Worker ${workerId} now listening on ${server.address()}`);
+    });
+  } else {
+    server.listen(+process.env.PORT || 4000, process.env.BIND || '0.0.0.0', () => {
+      log.info(`Worker ${workerId} now listening on ${server.address().address}:${server.address().port}`);
+    });
+  }
 
   const onExit = () => {
     log.info(`Worker ${workerId} exiting, bye bye`);