EPR LAPS Backend supports forward proxy configuration for outbound HTTP/HTTPS requests. This is essential in CDP environments where external API calls must route through a proxy.
The proxy is configured via the HTTP_PROXY environment variable and is automatically applied to multiple HTTP clients.
The proxy is configured in src/common/helpers/proxy/setup-proxy.js:
import { ProxyAgent, setGlobalDispatcher } from 'undici'import { bootstrap } from 'global-agent'import { createLogger } from '../logging/logger.js'import { config } from '../../../config.js'const logger = createLogger()/** * If HTTP_PROXY is set setupProxy() will enable it globally * for a number of http clients. * Node Fetch will still need to pass a ProxyAgent in on each call. */export function setupProxy() { const proxyUrl = config.get('httpProxy') if (proxyUrl) { logger.info('setting up global proxies') // Undici proxy setGlobalDispatcher(new ProxyAgent(proxyUrl)) // global-agent (axios/request/and others) bootstrap() globalThis.GLOBAL_AGENT.HTTP_PROXY = proxyUrl }}
Undici is the recommended HTTP client and has global proxy support via setGlobalDispatcher.
Using undici with global proxy:
import { fetch } from 'undici'// Proxy is automatically applied via setGlobalDispatcherconst response = await fetch('http://localhost:3001/data')const data = await response.json()
The global dispatcher is set in setupProxy(), so all undici fetch calls automatically use the proxy.
Node Fetch: Must manually pass dispatcher option (see example above)Axios/Request: Should work via global-agent automaticallyUndici: Should work via setGlobalDispatcher automatically