Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ProxyAgent, setGlobalDispatcher } from "undici";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Defer undici import until Node runtime is confirmed

The NEXT_RUNTIME guard in register() does not protect edge execution because undici is imported eagerly at module load time. In Next.js instrumentation, this file is evaluated before that guard runs, so any edge runtime context (for example, adding middleware or an edge route) can fail while resolving this Node-oriented dependency, causing build/startup errors before line 8 is reached. Load undici inside the nodejs branch (e.g., dynamic import) so non-Node runtimes never evaluate it.

Useful? React with 👍 / 👎.


function getProxyUrl(): string | undefined {
return process.env.PROXIMO_URL || process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
}

export async function register() {
if (process.env.NEXT_RUNTIME !== "nodejs") {
return;
}

const proxyUrl = getProxyUrl();
if (!proxyUrl) {
return;
}

setGlobalDispatcher(new ProxyAgent(proxyUrl));
console.log("Configured global fetch proxy via environment variable.");
}
Loading
Loading