refactored constants

This commit is contained in:
Sami Salkosuo 2020-04-14 15:20:50 +03:00
parent ef7d25f7d4
commit 52553229fa
2 changed files with 13 additions and 10 deletions

View File

@ -5,7 +5,6 @@ const Busboy = require('busboy');
const compression = require('compression'); const compression = require('compression');
const ffmpeg = require('fluent-ffmpeg'); const ffmpeg = require('fluent-ffmpeg');
const uniqueFilename = require('unique-filename'); const uniqueFilename = require('unique-filename');
const consts = require('./constants.js');
const endpoints = require('./endpoints.js'); const endpoints = require('./endpoints.js');
//const winston = require('winston'); //const winston = require('winston');
@ -28,6 +27,11 @@ const logger = createLogger({
})] })]
}); });
//constants
fileSizeLimit = 524288000;
port = 3000;
timeout = 3600000;
// catch SIGINT and SIGTERM and exit // catch SIGINT and SIGTERM and exit
// Using a single function to handle multiple signals // Using a single function to handle multiple signals
function handle(signal) { function handle(signal) {
@ -39,6 +43,8 @@ process.on('SIGINT', handle);
//SIGTERM is sent to terminate process, for example docker stop sends SIGTERM //SIGTERM is sent to terminate process, for example docker stop sends SIGTERM
process.on('SIGTERM', handle); process.on('SIGTERM', handle);
app.use(compression()); app.use(compression());
for (let prop in endpoints.types) { for (let prop in endpoints.types) {
@ -54,7 +60,7 @@ for (let prop in endpoints.types) {
headers: req.headers, headers: req.headers,
limits: { limits: {
files: 1, files: 1,
fileSize: consts.fileSizeLimit, fileSize: fileSizeLimit,
}}); }});
busboy.on('filesLimit', function() { busboy.on('filesLimit', function() {
logger.error(JSON.stringify({ 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 host = server.address().address;
let port = server.address().port; let port = server.address().port;
logger.info(JSON.stringify({ logger.info(JSON.stringify({
@ -187,11 +193,11 @@ const server = app.listen(consts.port, function() {
server.on('connection', function(socket) { server.on('connection', function(socket) {
logger.log('debug',JSON.stringify({ logger.log('debug',JSON.stringify({
action: 'new connection', action: 'new connection',
timeout: consts.timeout, timeout: timeout,
})); }));
socket.setTimeout(consts.timeout); socket.setTimeout(timeout);
socket.server.timeout = consts.timeout; socket.server.timeout = timeout;
server.keepAliveTimeout = consts.timeout; server.keepAliveTimeout = timeout;
}); });
app.use(function(req, res, next) { app.use(function(req, res, next) {

View File

@ -1,3 +0,0 @@
exports.fileSizeLimit = 524288000;
exports.port = 3000;
exports.timeout = 3600000;