MCPcopy Create free account
hub / github.com/langgenius/dify / createDevProxyRuntime

Function createDevProxyRuntime

packages/dev-proxy/src/cli.ts:58–100  ·  view source on GitHub ↗
(initialConfig: DevProxyConfig, cliOptions: DevProxyCliOptions)

Source from the content-addressed store, hash-verified

56}
57
58const createDevProxyRuntime = (initialConfig: DevProxyConfig, cliOptions: DevProxyCliOptions) => {
59 let runtime = startDevProxyServer(initialConfig, cliOptions)
60 let reloadTask = Promise.resolve()
61
62 console.log(`[dev-proxy] listening on http://${runtime.host}:${runtime.port}`)
63
64 const reload = async (nextConfig: unknown, reason: string) => {
65 assertDevProxyConfig(nextConfig)
66 const nextServerOptions = resolveDevProxyServerOptions(nextConfig.server, cliOptions)
67
68 if (runtime.host === nextServerOptions.host && runtime.port === nextServerOptions.port) {
69 runtime.updateConfig(nextConfig)
70 console.log(`[dev-proxy] reloaded ${reason}`)
71 return
72 }
73
74 await closeServer(runtime.server)
75 runtime = startDevProxyServer(nextConfig, cliOptions)
76 console.log(`[dev-proxy] restarted on http://${runtime.host}:${runtime.port} after ${reason}`)
77 }
78
79 const enqueueReload = (loadConfig: () => Promise<unknown> | unknown, reason: string) => {
80 reloadTask = reloadTask.then(async () => {
81 try {
82 await reload(await loadConfig(), reason)
83 }
84 catch (error) {
85 console.error(`[dev-proxy] failed to reload ${reason}`)
86 console.error(error instanceof Error ? error.message : error)
87 }
88 })
89
90 return reloadTask
91 }
92
93 return {
94 enqueueReload,
95 close: async () => {
96 await reloadTask
97 await closeServer(runtime.server)
98 },
99 }
100}
101
102async function main() {
103 const cliOptions = parseDevProxyCliArgs(process.argv.slice(2))

Callers 1

mainFunction · 0.85

Calls 4

startDevProxyServerFunction · 0.85
closeServerFunction · 0.85
resolveMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected