Skip to content

ft: add functions-loopback flag for Docker #7106

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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,469 changes: 4,219 additions & 250 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
"eslint-plugin-n": "^17.16.1",
"form-data": "4.0.2",
"is-ci": "4.1.0",
"markdown-magic": "^2.6.1",
"nock": "14.0.1",
"npm-run-all2": "^7.0.2",
"p-timeout": "6.1.4",
Expand Down
5 changes: 5 additions & 0 deletions src/commands/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ export const createDevCommand = (program: BaseCommand) => {
.conflicts('edgeInspect')
.argParser(validateShortFlagArgs),
)
.addOption(
new Option('--functions-loopback <host>', 'host for loopback requests to functions server')
.default('127.0.0.1')
.choices(['::1', '127.0.0.1']),
)
.addExamples([
'netlify dev',
'netlify dev -d public',
Expand Down
12 changes: 11 additions & 1 deletion src/commands/functions/functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OptionValues } from 'commander'
import { Option, OptionValues } from 'commander'

import { chalk } from '../../utils/command-helpers.js'
import requiresSiteInfo from '../../utils/hooks/requires-site-info.js'
Expand Down Expand Up @@ -61,6 +61,11 @@ export const createFunctionsCommand = (program: BaseCommand) => {
)
.option('--port <port>', 'Port where netlify dev is accessible. e.g. 8888', (value) => Number.parseInt(value))
.option('-o, --offline', 'Disables any features that require network access')
.addOption(
new Option('--functions-loopback <host>', 'host for loopback requests to functions server')
.default('127.0.0.1')
.choices(['::1', '127.0.0.1']),
)
.addExamples([
'netlify functions:invoke',
'netlify functions:invoke myfunction',
Expand Down Expand Up @@ -100,6 +105,11 @@ NOT the same as listing the functions that have been deployed. For that info you
.option('-f, --functions <dir>', 'Specify a functions directory to serve')
.option('-p, --port <port>', 'Specify a port for the functions server', (value) => Number.parseInt(value))
.option('-o, --offline', 'Disables any features that require network access')
.addOption(
new Option('--functions-loopback <host>', 'host for loopback requests to functions server')
.default('127.0.0.1')
.choices(['::1', '127.0.0.1']),
)
.addHelpText('after', 'Helpful for debugging functions.')
.action(async (options: OptionValues, command: BaseCommand) => {
const { functionsServe } = await import('./functions-serve.js')
Expand Down
5 changes: 5 additions & 0 deletions src/commands/serve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export const createServeCommand = (program: BaseCommand) =>
.argParser((value) => Number.parseInt(value))
.hideHelp(),
)
.addOption(
new Option('--functions-loopback <host>', 'host for loopback requests to functions server')
.default('127.0.0.1')
.choices(['::1', '127.0.0.1']),
)
.addExamples(['netlify serve', 'BROWSER=none netlify serve # disable browser auto opening'])
.action(async (options: Option, command: BaseCommand) => {
const { serve } = await import('./serve.js')
Expand Down
2 changes: 1 addition & 1 deletion src/lib/functions/runtimes/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const invokeFunction = async ({ context, environment, event, func, timeou
const client = createConnection(
{
port: result.streamPort,
host: 'localhost',
host: func.settings.functionsLoopback,
},
() => {
result.body = client
Expand Down
1 change: 1 addition & 0 deletions src/utils/detect-server-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ const detectServerSettings = async (

return {
...settings,
functionsLoopback: flags.functionsLoopback,
port: acquiredPort,
jwtSecret: devConfig.jwtSecret || 'secret',
jwtRolePath: devConfig.jwtRolePath || 'app_metadata.authorization.roles',
Expand Down
1 change: 1 addition & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type ServerSettings = BaseServerSettings & {
jwtRolePath: string
/** The port where the dev server is running on */
port: number
functionsLoopback: '::1' | '127.0.0.1'
/** The port where the functions are running on */
functionsPort: number
https?: { key: string; cert: string; keyFilePath: string; certFilePath: string }
Expand Down
Loading