-
Notifications
You must be signed in to change notification settings - Fork 366
/
proxy-server.ts
116 lines (110 loc) · 2.6 KB
/
proxy-server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import BaseCommand from '../commands/base-command.js'
import { $TSFixMe, NetlifyOptions } from '../commands/types.js'
import { BlobsContextWithEdgeAccess } from '../lib/blobs/blobs.js'
import { FunctionsRegistry } from '../lib/functions/registry.js'
import { exit, log, NETLIFYDEVERR } from './command-helpers.js'
import { startProxy } from './proxy.js'
import type StateConfig from './state-config.js'
import { ServerSettings } from './types.js'
interface InspectSettings {
// Inspect enabled
enabled: boolean
// Pause on breakpoints
pause: boolean
// Host/port override (optional)
address?: string
}
export const generateInspectSettings = (
edgeInspect: boolean | string,
edgeInspectBrk: boolean | string,
): InspectSettings => {
const enabled = Boolean(edgeInspect) || Boolean(edgeInspectBrk)
const pause = Boolean(edgeInspectBrk)
const getAddress = () => {
if (edgeInspect) {
return typeof edgeInspect === 'string' ? edgeInspect : undefined
}
if (edgeInspectBrk) {
return typeof edgeInspectBrk === 'string' ? edgeInspectBrk : undefined
}
}
return {
enabled,
pause,
address: getAddress(),
}
}
export const startProxyServer = async ({
accountId,
addonsUrls,
blobsContext,
command,
config,
configPath,
debug,
disableEdgeFunctions,
env,
functionsRegistry,
geoCountry,
geolocationMode,
getUpdatedConfig,
inspectSettings,
offline,
projectDir,
repositoryRoot,
settings,
site,
siteInfo,
state,
}: {
accountId: string
addonsUrls: $TSFixMe
blobsContext?: BlobsContextWithEdgeAccess
command: BaseCommand
config: NetlifyOptions['config']
// An override for the Netlify config path
configPath?: string
debug: boolean
disableEdgeFunctions: boolean
env: NetlifyOptions['cachedConfig']['env']
inspectSettings: InspectSettings
getUpdatedConfig: () => Promise<object>
geolocationMode: string
geoCountry: string
settings: ServerSettings
offline: boolean
site: $TSFixMe
siteInfo: $TSFixMe
projectDir: string
repositoryRoot?: string
state: StateConfig
functionsRegistry?: FunctionsRegistry
}) => {
const url = await startProxy({
addonsUrls,
blobsContext,
command,
config,
configPath: configPath || site.configPath,
debug,
disableEdgeFunctions,
env,
functionsRegistry,
geolocationMode,
geoCountry,
getUpdatedConfig,
inspectSettings,
offline,
projectDir,
settings,
state,
siteInfo,
accountId,
repositoryRoot,
})
if (!url) {
log(NETLIFYDEVERR, `Unable to start proxy server on port '${settings.port}'`)
exit(1)
}
return url
}