Skip to content

Commit

Permalink
fix(config): Properly parse time values from EENGINE_MAX_PAYLOAD_TIME…
Browse files Browse the repository at this point in the history
…OUT config option
  • Loading branch information
andris9 committed Feb 20, 2024
1 parent 4c09f8a commit c3f5ac7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
4 changes: 4 additions & 0 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ module.exports = {
},

getByteSize(val) {
if (typeof val === 'number') {
return val;
}

val = (val || '').toString().replace(/^([\d.]+)\s*([kMGTP])B?$/i, (o, num, m) => {
if (!num || isNaN(num)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"bull-arena": "4.2.0",
"bullmq": "5.2.1",
"compare-versions": "6.1.0",
"dotenv": "16.4.4",
"dotenv": "16.4.5",
"encoding-japanese": "2.0.0",
"exponential-backoff": "3.1.1",
"express": "4.18.2",
Expand Down
8 changes: 5 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,11 @@ const startApplication = async () => {
await settings.set('cookiePassword', cookiePassword);
}

// -- START WORKER THREADS

// single worker for HTTP, start first for health checks
await spawnWorker('api');

// multiple IMAP connection handlers
let workerPromises = [];
for (let i = 0; i < config.workers.imap; i++) {
Expand Down Expand Up @@ -2246,9 +2251,6 @@ const startApplication = async () => {
// single IMAP proxy interface worker
await spawnWorker('imapProxy');
}

// single worker for HTTP, start last to avoid running API requests for still-missing targets
await spawnWorker('api');
};

startApplication()
Expand Down
17 changes: 15 additions & 2 deletions workers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const IMAP_WORKER_COUNT = getWorkerCount(readEnvValue('EENGINE_WORKERS') || (con
const MAX_BODY_SIZE = getByteSize(readEnvValue('EENGINE_MAX_BODY_SIZE') || config.api.maxBodySize) || DEFAULT_MAX_BODY_SIZE;

// Payload reception timeout in milliseconds for message upload requests
const MAX_PAYLOAD_TIMEOUT = getByteSize(readEnvValue('EENGINE_MAX_PAYLOAD_TIMEOUT') || config.api.maxPayloadTimeout) || DEFAULT_MAX_PAYLOAD_TIMEOUT;
const MAX_PAYLOAD_TIMEOUT = getDuration(readEnvValue('EENGINE_MAX_PAYLOAD_TIMEOUT') || config.api.maxPayloadTimeout) || DEFAULT_MAX_PAYLOAD_TIMEOUT;

// CORS configuration for API requests
// By default, CORS is not enabled
Expand Down Expand Up @@ -234,7 +234,20 @@ const CORS_CONFIG = !CORS_ORIGINS
credentials: true
};

logger.debug({ msg: 'CORS config for API requests', cors: CORS_CONFIG });
logger.info({
msg: 'API server configuration',
api: {
port: API_PORT,
host: API_HOST,
maxPayloadTimeout: MAX_PAYLOAD_TIMEOUT,
maxBodySize: MAX_BODY_SIZE,
maxSize: MAX_ATTACHMENT_SIZE
},
service: {
commandTimeout: EENGINE_TIMEOUT
},
cors: CORS_CONFIG
});

const TRACKER_IMAGE = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64');

Expand Down

0 comments on commit c3f5ac7

Please sign in to comment.