forked from remotestorage/armadietto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharmadietto.js
executable file
·94 lines (81 loc) · 2.47 KB
/
armadietto.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env node
const Armadietto = require('../lib/armadietto');
const path = require('path');
const fs = require('fs');
const remoteStorageServer = {
// read and return configuration file
readConf (confPath) {
return JSON.parse(fs.readFileSync(confPath, 'utf8'));
},
// parse cli args
parseArgs () {
const ArgumentParser = require('argparse').ArgumentParser;
const version = require(path.join(__dirname, '/../package.json')).version;
const parser = new ArgumentParser({
add_help: true,
description: 'NodeJS remoteStorage server / ' + version
});
parser.add_argument('-c', '--conf', {
help: 'Path to configuration'
});
parser.add_argument('-e', '--exampleConf', {
help: 'Print configuration example',
action: 'store_true'
});
return parser.parse_args();
},
init () {
const args = this.parseArgs();
let conf = {};
if (args.exampleConf) {
console.log(fs.readFileSync(path.join(__dirname, '/conf.example.json'), 'utf8'));
return -1;
}
if (!args.conf) {
console.error('[ERR] Configuration file needed (help with -h)');
return -1;
}
try {
conf = this.readConf(args.conf);
} catch (e) {
console.error(e.toString());
return -1;
}
process.umask(0o077);
const store = new Armadietto.FileTree({ path: conf.storage_path, lock_timeout_ms: conf.lock_timeout_ms, lock_stale_after_ms: conf.lock_stale_after_ms });
const middleware = [ // order matters: on each request middleware called in order defined below
require('../lib/extensions/rate_limiter/rate_limiter'),
require('../lib/extensions/storage_allowance/storage_allowance'),
require('../lib/extensions/pay2myapp/pay2myapp')
];
const server = new Armadietto({
basePath: conf.basePath,
store,
middleware,
logging: conf.logging,
http: {
host: conf.http.host,
port: conf.http.port
},
https: conf.https
? {
host: conf.https.host,
port: conf.https.enable && conf.https.port,
force: conf.https.force,
cert: conf.https.cert,
key: conf.https.key
}
: {},
allow: {
signup: conf.allow_signup || false
},
tosUrl: conf.terms_of_service_url,
cacheViews: conf.cache_views || false,
extensions: conf.extensions
});
server.boot();
}
};
if (require.main === module) {
remoteStorageServer.init();
}