Repository navigation
Expand file tree
/
Copy pathapi.js
More file actions
71 lines (66 loc) · 1.78 KB
/
Copy pathapi.js
File metadata and controls
71 lines (66 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import Server from './lib/Server.js';
const argv = yargs(hideBin(process.argv))
.locale('en')
.option('clientKey', {
alias: 'k',
type: 'string',
description: 'Client API key'
})
.option('workers', {
alias: 'm',
type: 'number',
description: 'Maximum concurrent tasks',
default: 1
})
.option('port', {
alias: 'p',
type: 'number',
description: 'Server port to listen',
default: 3000
})
.option('host', {
alias: 'h',
type: 'string',
description: 'Server host to listen',
default: 'localhost'
})
.option('timeout', {
alias: 't',
type: 'number',
description: 'Timeout per task in seconds',
default: 60
})
.option('logError', {
alias: 'l',
type: 'boolean',
description: 'Enable error logging',
default: false
})
.argv;
const config = {
clientKey: argv.clientKey || process.env.CLOUDFREED_CLIENT_KEY,
maxConcurrentTasks: argv.workers || parseInt(process.env.CLOUDFREED_WORKERS, 10) || 1,
port: argv.port || parseInt(process.env.CLOUDFREED_PORT, 10) || 3000,
host: argv.host || process.env.CLOUDFREED_HOST || "localhost",
timeout: argv.timeout || parseInt(process.env.CLOUDFREED_TASK_TIMEOUT, 10) || 60,
logError: argv.logError || false,
};
const server = new Server(config);
await server.initialize();
const httpServer = server.listen();
process.on('SIGTERM', async () => {
console.log('Received SIGTERM signal. Shutting down gracefully...');
await server.stop();
httpServer.close(() => {
process.exit(0);
});
});
process.on('SIGINT', async () => {
console.log('Received SIGINT signal. Shutting down gracefully...');
await server.stop();
httpServer.close(() => {
process.exit(0);
});
});