From 97a6c813410f7a483404a59d938df771b6be9441 Mon Sep 17 00:00:00 2001 From: Angel Garcia Date: Thu, 11 Jun 2020 16:41:45 +0200 Subject: [PATCH] Improved app start - now showing real address - unix socket support - string corrections --- package.json | 2 +- src/app.js | 2 +- src/index.js | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 0e3387c..86362d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aruppi", - "version": "2.0.0", + "version": "2.0.1", "description": "Aruppi is a custom API to obtain data from the Japanese culture for the mobile app", "main": "./src/api/api.js", "scripts": { diff --git a/src/app.js b/src/app.js index edc0ea4..73594c5 100644 --- a/src/app.js +++ b/src/app.js @@ -26,7 +26,7 @@ app.get('/api/', (req, res) => { app.get('/api/v1', (req, res) => { res.json({ - message: 'Sorry, version (api/v1) is deprecated, if you want to see content go to api/v2' + message: 'Sorry, version v1 is deprecated, if you want to see content go to v2' }); }); diff --git a/src/index.js b/src/index.js index 96f95b7..5a6be1b 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,20 @@ const app = require('./app'); const port = process.env.PORT || 5000; +const addr = isNaN(port) ? + '' : + (process.env.ADDR || '0.0.0.0'); -app.listen(port, () => { +server = app.listen(port, addr, () => { /* eslint-disable no-console */ - console.log(`\nšŸš€ ... Listening: http://localhost:${port}/api/v2`); + console.log(`\nšŸš€ ... Listening: ${addr}${addr ? '\:' : 'unix://'}${port}`); /* eslint-enable no-console */ }); + +function shutdown() { + server.close(); // socket file is automatically removed here + process.exit(); +} + +process.on('SIGINT', shutdown); +process.on('SIGQUIT', shutdown); +process.on('SIGTERM', shutdown);