This repository was archived by the owner on Jan 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathucwa-proxy.js
More file actions
50 lines (43 loc) · 1.28 KB
/
Copy pathucwa-proxy.js
File metadata and controls
50 lines (43 loc) · 1.28 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
'use strict';
var fs = require('fs');
var argv = require('minimist')(process.argv.slice(2), {
string: ['pfx', 'passphrase', 'origin'],
boolean: ['secure', 'logging'],
default: {
port: 4666,
secure: true,
pfx: __dirname + '\\certs\\node-ucwa.pfx',
passphrase: '',
logging: false,
origin: '*'
}
});
var ucwaproxy = require('./proxy');
function parseArgs () {
var options = {
port: argv.port,
secure: argv.secure,
cert: {
pfx: argv.pfx,
passphrase: argv.passphrase
},
logging: argv.logging,
origin: argv.origin
};
if (options.secure === false) {
delete options.cert;
} else if (options.secure === true && (!options.cert.pfx)) {
throw new Error('When using secure (Https) pfx is required!');
} else if (options.secure === true && !fs.existsSync(options.cert.pfx)) {
throw new Error('Unable to find certificate specified at path: ' + options.cert.pfx);
}
if (options.cert) {
options.cert.pfx = fs.readFileSync(options.cert.pfx);
if (options.cert.passphrase === '') {
delete options.cert.passphrase;
}
}
return options;
}
var options = parseArgs();
var proxy = ucwaproxy(options);