-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation.ts
More file actions
36 lines (34 loc) · 1004 Bytes
/
instrumentation.ts
File metadata and controls
36 lines (34 loc) · 1004 Bytes
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
export async function register() {
console.log("registering instrumentation");
if (
process.env.NODE_ENV === "development" &&
process.env.NEXT_RUNTIME === "nodejs"
) {
// Improve stack traces in dev
Error.stackTraceLimit = 100;
process.on("unhandledRejection", (reason) => {
console.error(
"unhandledRejection:",
reason instanceof Error ? reason.stack ?? reason : reason
);
});
process.on("uncaughtException", (err) => {
console.error("uncaughtException:", err.stack ?? err);
});
const proxyUrl = "http://localhost:8888";
try {
await fetch(proxyUrl);
} catch {
console.error("MITM proxy not running");
throw new Error("MITM proxy not running");
}
const undici = await import("undici");
const proxyAgent = new undici.ProxyAgent({
uri: proxyUrl,
requestTls: { rejectUnauthorized: false },
proxyTls: { rejectUnauthorized: false },
});
undici.setGlobalDispatcher(proxyAgent);
console.log(`Global proxy enabled via ${proxyUrl}`);
}
}