]> cat aescling's git repositories - mastodon.git/blobdiff - streaming/index.js
Allow to listen Unix socket (#2085)
[mastodon.git] / streaming / index.js
index 366a39a6a287281b8945d74e9ae07205acab56c4..c7959b3069e02f7b4f5b5fada1d7b8d0fe494f8e 100644 (file)
@@ -19,7 +19,7 @@ dotenv.config({
 if (cluster.isMaster) {
   // cluster master
 
-  const core = +process.env.STREAMING_CLUSTER_NUM || (env === 'development' ? 1 : os.cpus().length - 1)
+  const core = +process.env.STREAMING_CLUSTER_NUM || (env === 'development' ? 1 : (os.cpus().length > 1 ? os.cpus().length - 1 : 1))
   const fork = () => {
     const worker = cluster.fork();
     worker.on('exit', (code, signal) => {
@@ -285,11 +285,11 @@ if (cluster.isMaster) {
   })
 
   app.get('/api/v1/streaming/hashtag', (req, res) => {
-    streamFrom(`timeline:hashtag:${req.params.tag}`, req, streamToHttp(req, res), streamHttpEnd(req), true)
+    streamFrom(`timeline:hashtag:${req.query.tag}`, req, streamToHttp(req, res), streamHttpEnd(req), true)
   })
 
   app.get('/api/v1/streaming/hashtag/local', (req, res) => {
-    streamFrom(`timeline:hashtag:${req.params.tag}:local`, req, streamToHttp(req, res), streamHttpEnd(req), true)
+    streamFrom(`timeline:hashtag:${req.query.tag}:local`, req, streamToHttp(req, res), streamHttpEnd(req), true)
   })
 
   wss.on('connection', ws => {
@@ -328,6 +328,14 @@ if (cluster.isMaster) {
 
   server.listen(process.env.PORT || 4000, () => {
     log.level = process.env.LOG_LEVEL || 'verbose'
-    log.info(`Starting streaming API server worker on port ${server.address().port}`)
+    log.info(`Starting streaming API server worker on ${server.address()}`)
   })
+
+  process.on('SIGINT', exit)
+  process.on('SIGTERM', exit)
+  process.on('exit', exit)
+
+  function exit() {
+    server.close()
+  }
 }
This page took 0.026428 seconds and 3 git commands to generate.