-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathserver.ts
More file actions
59 lines (53 loc) · 1.96 KB
/
Copy pathserver.ts
File metadata and controls
59 lines (53 loc) · 1.96 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
51
52
53
54
55
56
57
58
59
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { ReplayingCapiProxy } from "./replayingCapiProxy";
import { ConnectProxy } from "./connectProxy";
import { createE2eRequestHandler } from "./mockHandlers";
// Starts up an instance of the ReplayingCapiProxy server
// The intention is for this to be usable in E2E tests across all languages
const proxy = new ReplayingCapiProxy("https://api.githubcopilot.com");
const proxyUrl = await proxy.start();
const blockedHosts: string[] = [];
const unhandledRequests: string[] = [];
const connectProxy = new ConnectProxy(
createE2eRequestHandler({
capiProxyUrl: proxyUrl,
onUnhandled: (host, method, requestPath) => {
const entry = `${method} ${host}${requestPath}`;
unhandledRequests.push(entry);
console.error(`[E2E proxy] Unhandled intercepted request: ${entry}`);
},
}),
{
interceptDomains: [
"api.githubcopilot.com",
"api.github.com",
"github.com",
"api.mcp.github.com",
],
passthroughDomains: ["registry.npmjs.org"],
onBlockedConnection: (host, port) => {
const entry = `${host}:${port}`;
blockedHosts.push(entry);
console.error(`[E2E proxy] Blocked connection to: ${entry}`);
},
},
);
await connectProxy.start();
proxy.onStopRequested = async () => {
if (blockedHosts.length || unhandledRequests.length) {
const details = [
...blockedHosts.map((host) => `blocked ${host}`),
...unhandledRequests.map((request) => `unhandled ${request}`),
].join(", ");
console.error(`[E2E proxy] Unexpected network activity: ${details}`);
}
await connectProxy.stop();
};
console.log(
`Listening: ${proxyUrl} ${JSON.stringify({
connectProxyUrl: connectProxy.proxyUrl,
caFilePath: connectProxy.caFilePath,
})}`,
);