-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
69 lines (58 loc) · 1.66 KB
/
Copy pathserver.js
File metadata and controls
69 lines (58 loc) · 1.66 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
const S3rver = require('s3rver');
const process = require('process');
let instance;
// Begin reading from stdin so the process does not exit.
process.stdin.resume();
process.on('SIGINT', () => {
console.log('Received SIGINT. Press Control-D to exit.');
});
// Using a single function to handle multiple signals
function handle(signal) {
console.log(`Received ${signal}`);
instance.close();
process.exit(0);
}
process.on('SIGINT', handle);
process.on('SIGTERM', handle);
process.on('SIGHUP', handle);
function stringToBool(str, defaultValue = false){
switch(str.toLowerCase().trim()){
case "true":
case "yes":
case "1":
return true;
case "false":
case "no":
case "0":
case null:
return false;
default:
return defaultValue
}
}
const port = process.env.PORT || 4569;
const address = process.env.HOST || 'localhost';
const resetOnClose = process.env.RESET_ON_CLOSE !== undefined
? stringToBool(process.env.RESET_ON_CLOSE)
: false;
let configureBuckets = [];
if (process.env.BUCKETS) {
configureBuckets = process.env.BUCKETS.split(',').map(v => ({ name: v }));
}
const options = {
port,
address,
silent: false,
directory: '/tmp/s3rver',
...(process.env.VHOST_BUCKETS !== undefined ? { vhostBuckets: stringToBool(process.env.VHOST_BUCKETS) } : {}),
configureBuckets,
resetOnClose
};
console.log('S3rver config: ',options)
instance = new S3rver(options).run((err, { address, port } = {}) => {
if (err) {
console.error(err);
} else {
console.log('S3rver listening at address %s:%d', address, port);
}
});