From 52553229fa565dda6a6697399e8535e22fb1add5 Mon Sep 17 00:00:00 2001 From: Sami Salkosuo Date: Tue, 14 Apr 2020 15:20:50 +0300 Subject: [PATCH] refactored constants --- src/app.js | 20 +++++++++++++------- src/constants.js | 3 --- 2 files changed, 13 insertions(+), 10 deletions(-) delete mode 100644 src/constants.js diff --git a/src/app.js b/src/app.js index 47c7565..1cbcc36 100644 --- a/src/app.js +++ b/src/app.js @@ -5,7 +5,6 @@ const Busboy = require('busboy'); const compression = require('compression'); const ffmpeg = require('fluent-ffmpeg'); const uniqueFilename = require('unique-filename'); -const consts = require('./constants.js'); const endpoints = require('./endpoints.js'); //const winston = require('winston'); @@ -28,6 +27,11 @@ const logger = createLogger({ })] }); +//constants +fileSizeLimit = 524288000; +port = 3000; +timeout = 3600000; + // catch SIGINT and SIGTERM and exit // Using a single function to handle multiple signals function handle(signal) { @@ -39,6 +43,8 @@ process.on('SIGINT', handle); //SIGTERM is sent to terminate process, for example docker stop sends SIGTERM process.on('SIGTERM', handle); + + app.use(compression()); for (let prop in endpoints.types) { @@ -54,7 +60,7 @@ for (let prop in endpoints.types) { headers: req.headers, limits: { files: 1, - fileSize: consts.fileSizeLimit, + fileSize: fileSizeLimit, }}); busboy.on('filesLimit', function() { logger.error(JSON.stringify({ @@ -174,7 +180,7 @@ require('express-readme')(app, { }); -const server = app.listen(consts.port, function() { +const server = app.listen(port, function() { let host = server.address().address; let port = server.address().port; logger.info(JSON.stringify({ @@ -187,11 +193,11 @@ const server = app.listen(consts.port, function() { server.on('connection', function(socket) { logger.log('debug',JSON.stringify({ action: 'new connection', - timeout: consts.timeout, + timeout: timeout, })); - socket.setTimeout(consts.timeout); - socket.server.timeout = consts.timeout; - server.keepAliveTimeout = consts.timeout; + socket.setTimeout(timeout); + socket.server.timeout = timeout; + server.keepAliveTimeout = timeout; }); app.use(function(req, res, next) { diff --git a/src/constants.js b/src/constants.js deleted file mode 100644 index fa6fea1..0000000 --- a/src/constants.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.fileSizeLimit = 524288000; -exports.port = 3000; -exports.timeout = 3600000;