-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
49 lines (44 loc) · 1.68 KB
/
index.ts
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
#!/usr/local/bin
import {Daemon} from './localServer/localServer'
import { proxyServer as proxyServer_class } from './localServer/proxyServer'
const yargs = require('yargs')
const argv = yargs(process.argv.slice(2))
.usage('Usage: yarn run seguro-gateway --port [number] --path [string]')
.help('h')
.alias('h', 'help')
.describe('port', 'Run Seguro Gateway on this port.')
.describe('path', 'Read worker files on this path.')
.example('seguro-gateway --port 3001', 'Run Seguro Gateway on PORT 3001')
.example('seguro-gateway --path ./', 'Read worker files on current directory.')
.example('seguro-gateway --port 3001 --path ./', 'Read worker files on current directory & run Seguro Gateway on PORT 3001.')
.check(function (argv: any) {
if (argv.port) {
if (typeof argv.port !== 'number') {
console.log('Invalid port argument.')
process.exit(1)
}
}
if (argv.path) {
if (typeof argv.path !== 'string') {
console.log('Invalid path argument.')
process.exit(1)
}
}
return true;
})
.argv
let PORT = 3001
let PATH = ''
export const launchDaemon = (port: number, path: string) => {
new Daemon ( port, path )
}
export const proxyServer = (post: string, entryNode: nodes_info, _egressNode: nodes_info, privateKey: string) => new proxyServer_class(post, [entryNode], [_egressNode], privateKey, false, '')
if (argv.port || argv.path) {
PATH = argv.path
if (typeof argv.port === 'number') {
PORT = argv.port
} else {
console.log('Invalid PORT, running on PORT 3001.')
}
launchDaemon(PORT, PATH)
}