forked from hummingbot/gateway
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttps.ts
More file actions
executable file
·50 lines (45 loc) · 1.31 KB
/
https.ts
File metadata and controls
executable file
·50 lines (45 loc) · 1.31 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
import { Application } from 'express';
import fs from 'fs';
import https from 'https';
import { ConfigManagerCertPassphrase } from './services/config-manager-cert-passphrase';
import { ConfigManagerV2 } from './services/config-manager-v2';
export const addHttps = (app: Application) => {
const serverKey = fs.readFileSync(
addSlashToPath(
ConfigManagerV2.getInstance().get('server.certificatePath')
) + 'server_key.pem',
{ encoding: 'utf-8' }
);
const serverCert = fs.readFileSync(
addSlashToPath(
ConfigManagerV2.getInstance().get('server.certificatePath')
) + 'server_cert.pem',
{ encoding: 'utf-8' }
);
const caCert = fs.readFileSync(
addSlashToPath(
ConfigManagerV2.getInstance().get('server.certificatePath')
) + 'ca_cert.pem',
{ encoding: 'utf-8' }
);
return https.createServer(
{
key: serverKey,
cert: serverCert,
// request client certificate from user
requestCert: true,
// reject requests with no valid certificate
rejectUnauthorized: true,
// use ca cert created with own key for self-signed
ca: [caCert],
passphrase: ConfigManagerCertPassphrase.readPassphrase(),
},
app
);
};
const addSlashToPath = (path: string) => {
if (!path.endsWith('/')) {
path += '/';
}
return path;
};