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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"@netlify/edge-functions-bootstrap": "^3.2.0",
"@netlify/headers-parser": "^10.1.1",
"@netlify/images": "^1.3.12",
"@netlify/local-functions-proxy": "^2.0.3",
"@netlify/redirect-parser": "^16.1.0",
"@netlify/zip-it-and-ship-it": "^15.3.3",
"@octokit/rest": "^22.0.0",
Expand Down Expand Up @@ -215,6 +214,9 @@
"verdaccio": "^6.3.2",
"vitest": "^3.2.4"
},
"optionalDependencies": {
"@netlify/local-functions-proxy": "^2.0.3"
},
"engines": {
"node": ">=22.13.0"
},
Expand Down
23 changes: 16 additions & 7 deletions src/lib/functions/local-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { stdout } from 'process'
import execa from '../../utils/execa.js'

import { getBinaryPath as getFunctionsProxyPath } from '@netlify/local-functions-proxy'
let getFunctionsProxyPath: (() => Promise<string | null>) | null = null

import execa from '../../utils/execa.js'
async function loadFunctionsProxy() {
if (getFunctionsProxyPath === null) {
try {
const mod = await import('@netlify/local-functions-proxy')
getFunctionsProxyPath = mod.getBinaryPath
} catch {
// Package not installed (e.g., when using --omit=optional)
getFunctionsProxyPath = () => Promise.resolve(null)
}
}
return getFunctionsProxyPath
}

export const runFunctionsProxy = async ({
binaryPath,
Expand All @@ -19,7 +31,8 @@ export const runFunctionsProxy = async ({
name: string
timeout: number
}) => {
const functionsProxyPath = await getFunctionsProxyPath()
const getBinaryPath = await loadFunctionsProxy()
const functionsProxyPath = await getBinaryPath()
const requestData = {
resource: '',
...event,
Expand All @@ -33,11 +46,9 @@ export const runFunctionsProxy = async ({
requestTimeEpoch: 0,
},
}

if (functionsProxyPath === null) {
throw new Error('Host machine does not support local functions proxy server')
}

const parameters = [
'--event',
JSON.stringify(requestData),
Expand All @@ -51,8 +62,6 @@ export const runFunctionsProxy = async ({
`${timeout.toString()}s`,
]
const proxyProcess = execa(functionsProxyPath, parameters)

proxyProcess.stderr?.pipe(stdout)

return proxyProcess
}