-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientFetch.ts
49 lines (41 loc) · 1.11 KB
/
clientFetch.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
import fetch from 'node-fetch';
import https from 'https';
import fs from 'fs';
import { config } from './config';
const apiUrl = 'https://localhost:3000'; // Replace with your server URL
// const clientCert = fs.readFileSync('client.crt', 'utf-8').toString();
// const clientKey = fs.readFileSync('client-private-key.pem', 'utf-8').toString();
// const rootCA = fs.readFileSync('rootCA.crt', 'utf-8').toString()
const clientCert = fs.readFileSync(config.CLIENT_CERT);
const clientKey = fs.readFileSync(config.CLIENT_PRIVATE_KEY);
const rootCA = fs.readFileSync(config.ROOT_CA_CERT);
console.log({
cert: clientCert,
key: clientKey,
ca: rootCA,
rejectUnauthorized: false
});
const agent = new https.Agent({
cert: clientCert,
key: clientKey,
ca: rootCA,
rejectUnauthorized: false
});
const run = async () => {
const response = await fetch(apiUrl, { agent });
// const response = await fetch(apiUrl);
const data = await response.text();
console.log({
response,
data,
});
}
(async () => {
try {
await run();
} catch(err){
console.log(err);
process.exit(1);
}
process.exit(0);
})();