MCPcopy Create free account
hub / github.com/netlify/cli / startServer

Function startServer

tests/integration/utils/dev-server.ts:71–243  ·  view source on GitHub ↗
({
  args = [],
  command,
  context = 'dev',
  cwd,
  debug = false,
  env = {},
  expectFailure = false,
  framework,
  offline = true,
  prompt,
  serve = false,
  skipWaitPort = false,
  targetPort,
}: DevServerOptions)

Source from the content-addressed store, hash-verified

69const SERVER_START_TIMEOUT = 24e4
70
71const startServer = async ({
72 args = [],
73 command,
74 context = 'dev',
75 cwd,
76 debug = false,
77 env = {},
78 expectFailure = false,
79 framework,
80 offline = true,
81 prompt,
82 serve = false,
83 skipWaitPort = false,
84 targetPort,
85}: DevServerOptions): Promise<DevServer | { timeout: boolean; output: string; error?: string; report?: string }> => {
86 const port = await getPort()
87 const host = 'localhost'
88 const url = `http://${host}:${port}`
89
90 console.log(`Starting dev server on port: ${port} in directory ${path.basename(cwd)}`)
91 const baseCommand = serve ? 'serve' : 'dev'
92 const baseArgs = [
93 baseCommand,
94 offline ? '--offline' : '',
95 '-p',
96 port.toString(),
97 debug ? '--debug' : '',
98 skipWaitPort ? '--skip-wait-port' : '',
99 ]
100
101 if (targetPort) {
102 baseArgs.push('--target-port', targetPort.toString())
103 } else {
104 const staticPort = await getPort()
105 baseArgs.push('--staticServerPort', staticPort.toString())
106 }
107
108 if (framework) {
109 baseArgs.push('--framework', framework)
110 }
111
112 if (command) {
113 baseArgs.push('--command', command)
114 }
115
116 // We use `null` to override the default context and actually omit the flag
117 // from the command, which is useful in some test scenarios.
118 if (context !== null) {
119 baseArgs.push('--context', context)
120 }
121
122 const ps = execa(cliPath, [...baseArgs, ...args], getExecaOptions({ cwd, env }))
123
124 if (process.env.DEBUG_TESTS) {
125 ps.stderr!.pipe(process.stderr)
126 ps.stdout!.pipe(process.stdout)
127 }
128

Callers 1

startDevServerFunction · 0.85

Calls 5

getExecaOptionsFunction · 0.85
handleQuestionsFunction · 0.85
resolveFunction · 0.85
logMethod · 0.80
onMethod · 0.80

Tested by

no test coverage detected