netlify-cli 17.19.5 → 17.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
- declare const createStreamPromise: (stream: any, timeoutSeconds: any, bytesLimit?: number) => Promise<unknown>;
1
+ import { Buffer } from 'buffer';
2
+ import { IncomingMessage } from 'http';
3
+ declare const createStreamPromise: (stream: IncomingMessage, timeoutSeconds: number, bytesLimit?: number) => Promise<Buffer>;
2
4
  export default createStreamPromise;
3
5
  //# sourceMappingURL=create-stream-promise.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-stream-promise.d.ts","sourceRoot":"","sources":["../../src/utils/create-stream-promise.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,mBAAmB,6EAmDxB,CAAA;AAED,eAAe,mBAAmB,CAAA"}
1
+ {"version":3,"file":"create-stream-promise.d.ts","sourceRoot":"","sources":["../../src/utils/create-stream-promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAOtC,QAAA,MAAM,mBAAmB,WACf,eAAe,kBACP,MAAM,0BAErB,QAAQ,MAAM,CAyChB,CAAA;AAED,eAAe,mBAAmB,CAAA"}
@@ -2,31 +2,25 @@ import { Buffer } from 'buffer';
2
2
  const SEC_TO_MILLISEC = 1e3;
3
3
  // 6 MiB
4
4
  const DEFAULT_BYTES_LIMIT = 6e6;
5
- // @ts-expect-error TS(7006) FIXME: Parameter 'stream' implicitly has an 'any' type.
6
5
  const createStreamPromise = function (stream, timeoutSeconds, bytesLimit = DEFAULT_BYTES_LIMIT) {
7
6
  return new Promise(function streamPromiseFunc(resolve, reject) {
8
- // @ts-expect-error TS(7034) FIXME: Variable 'data' implicitly has type 'any[]' in som... Remove this comment to see the full error message
9
7
  let data = [];
10
8
  let dataLength = 0;
11
9
  // @ts-expect-error TS(7034) FIXME: Variable 'timeoutId' implicitly has type 'any' in ... Remove this comment to see the full error message
12
10
  let timeoutId = null;
13
11
  if (timeoutSeconds != null && Number.isFinite(timeoutSeconds)) {
14
12
  timeoutId = setTimeout(() => {
15
- // @ts-expect-error TS(2322) FIXME: Type 'null' is not assignable to type 'any[]'.
16
13
  data = null;
17
14
  reject(new Error('Request timed out waiting for body'));
18
15
  }, timeoutSeconds * SEC_TO_MILLISEC);
19
16
  }
20
- // @ts-expect-error TS(7006) FIXME: Parameter 'chunk' implicitly has an 'any' type.
21
17
  stream.on('data', function onData(chunk) {
22
- // @ts-expect-error TS(7005) FIXME: Variable 'data' implicitly has an 'any[]' type.
23
18
  if (!Array.isArray(data)) {
24
19
  // Stream harvesting closed
25
20
  return;
26
21
  }
27
22
  dataLength += chunk.length;
28
23
  if (dataLength > bytesLimit) {
29
- // @ts-expect-error TS(2322) FIXME: Type 'null' is not assignable to type 'any[]'.
30
24
  data = null;
31
25
  reject(new Error('Stream body too big'));
32
26
  }
@@ -34,18 +28,13 @@ const createStreamPromise = function (stream, timeoutSeconds, bytesLimit = DEFAU
34
28
  data.push(chunk);
35
29
  }
36
30
  });
37
- // @ts-expect-error TS(7006) FIXME: Parameter 'error' implicitly has an 'any' type.
38
31
  stream.on('error', function onError(error) {
39
- // @ts-expect-error TS(2322) FIXME: Type 'null' is not assignable to type 'any[]'.
40
32
  data = null;
41
33
  reject(error);
42
- // @ts-expect-error TS(7005) FIXME: Variable 'timeoutId' implicitly has an 'any' type.
43
34
  clearTimeout(timeoutId);
44
35
  });
45
36
  stream.on('end', function onEnd() {
46
- // @ts-expect-error TS(7005) FIXME: Variable 'timeoutId' implicitly has an 'any' type.
47
37
  clearTimeout(timeoutId);
48
- // @ts-expect-error TS(7005) FIXME: Variable 'data' implicitly has an 'any[]' type.
49
38
  if (data) {
50
39
  // @ts-expect-error TS(7005) FIXME: Variable 'data' implicitly has an 'any[]' type.
51
40
  resolve(Buffer.concat(data));
@@ -1,63 +1,36 @@
1
- /**
2
- * @typedef {Object} InspectSettings
3
- * @property {boolean} enabled - Inspect enabled
4
- * @property {boolean} pause - Pause on breakpoints
5
- * @property {string|undefined} address - Host/port override (optional)
6
- */
7
- /**
8
- * @param {boolean|string} edgeInspect
9
- * @param {boolean|string} edgeInspectBrk
10
- * @returns {InspectSettings}
11
- */
12
- export declare const generateInspectSettings: (edgeInspect: any, edgeInspectBrk: any) => {
1
+ import BaseCommand from '../commands/base-command.js';
2
+ import { $TSFixMe, NetlifyOptions } from '../commands/types.js';
3
+ import { BlobsContext } from '../lib/blobs/blobs.js';
4
+ import { FunctionsRegistry } from '../lib/functions/registry.js';
5
+ import type StateConfig from './state-config.js';
6
+ import { ServerSettings } from './types.js';
7
+ interface InspectSettings {
13
8
  enabled: boolean;
14
9
  pause: boolean;
15
- address: string | undefined;
16
- };
17
- /**
18
- *
19
- * @param {object} params
20
- * @param {string=} params.accountId
21
- * @param {*} params.addonsUrls
22
- * @param {import("../lib/blobs/blobs.js").BlobsContext} blobsContext
23
- * @param {import('../commands/types.js').NetlifyOptions["config"]} params.config
24
- * @param {string} [params.configPath] An override for the Netlify config path
25
- * @param {boolean} params.debug
26
- * @param {import('../commands/types.js').NetlifyOptions["cachedConfig"]['env']} params.env
27
- * @param {InspectSettings} params.inspectSettings
28
- * @param {() => Promise<object>} params.getUpdatedConfig
29
- * @param {string} params.geolocationMode
30
- * @param {string} params.geoCountry
31
- * @param {*} params.settings
32
- * @param {boolean} params.offline
33
- * @param {object} params.site
34
- * @param {*} params.siteInfo
35
- * @param {string} params.projectDir
36
- * @param {string} params.repositoryRoot
37
- * @param {import('./state-config.js').default} params.state
38
- * @param {import('../lib/functions/registry.js').FunctionsRegistry=} params.functionsRegistry
39
- * @returns
40
- */
10
+ address?: string;
11
+ }
12
+ export declare const generateInspectSettings: (edgeInspect: boolean | string, edgeInspectBrk: boolean | string) => InspectSettings;
41
13
  export declare const startProxyServer: ({ accountId, addonsUrls, blobsContext, command, config, configPath, debug, env, functionsRegistry, geoCountry, geolocationMode, getUpdatedConfig, inspectSettings, offline, projectDir, repositoryRoot, settings, site, siteInfo, state, }: {
42
- accountId: any;
43
- addonsUrls: any;
44
- blobsContext: any;
45
- command: any;
46
- config: any;
47
- configPath: any;
48
- debug: any;
49
- env: any;
50
- functionsRegistry: any;
51
- geoCountry: any;
52
- geolocationMode: any;
53
- getUpdatedConfig: any;
54
- inspectSettings: any;
55
- offline: any;
56
- projectDir: any;
57
- repositoryRoot: any;
58
- settings: any;
59
- site: any;
60
- siteInfo: any;
61
- state: any;
14
+ accountId: string;
15
+ addonsUrls: $TSFixMe;
16
+ blobsContext?: BlobsContext | undefined;
17
+ command: BaseCommand;
18
+ config: NetlifyOptions['config'];
19
+ configPath?: string | undefined;
20
+ debug: boolean;
21
+ env: NetlifyOptions['cachedConfig']['env'];
22
+ inspectSettings: InspectSettings;
23
+ getUpdatedConfig: () => Promise<object>;
24
+ geolocationMode: string;
25
+ geoCountry: string;
26
+ settings: ServerSettings;
27
+ offline: boolean;
28
+ site: $TSFixMe;
29
+ siteInfo: $TSFixMe;
30
+ projectDir: string;
31
+ repositoryRoot?: string | undefined;
32
+ state: StateConfig;
33
+ functionsRegistry?: FunctionsRegistry | undefined;
62
34
  }) => Promise<string>;
35
+ export {};
63
36
  //# sourceMappingURL=proxy-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy-server.d.ts","sourceRoot":"","sources":["../../src/utils/proxy-server.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH;;;;GAIG;AAEH,eAAO,MAAM,uBAAuB;;;;CAiBnC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;qBAqE5B,CAAA"}
1
+ {"version":3,"file":"proxy-server.d.ts","sourceRoot":"","sources":["../../src/utils/proxy-server.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,6BAA6B,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAIhE,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,UAAU,eAAe;IAEvB,OAAO,EAAE,OAAO,CAAA;IAEhB,KAAK,EAAE,OAAO,CAAA;IAEd,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,eAAO,MAAM,uBAAuB,gBACrB,OAAO,GAAG,MAAM,kBACb,OAAO,GAAG,MAAM,KAC/B,eAiBF,CAAA;AAED,eAAO,MAAM,gBAAgB;eAsBhB,MAAM;gBACL,QAAQ;;aAEX,WAAW;YACZ,cAAc,CAAC,QAAQ,CAAC;;WAGzB,OAAO;SACT,cAAc,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC;qBACzB,eAAe;sBACd,MAAM,QAAQ,MAAM,CAAC;qBACtB,MAAM;gBACX,MAAM;cACR,cAAc;aACf,OAAO;UACV,QAAQ;cACJ,QAAQ;gBACN,MAAM;;WAEX,WAAW;;qBA8BnB,CAAA"}
@@ -1,17 +1,5 @@
1
1
  import { exit, log, NETLIFYDEVERR } from './command-helpers.js';
2
2
  import { startProxy } from './proxy.js';
3
- /**
4
- * @typedef {Object} InspectSettings
5
- * @property {boolean} enabled - Inspect enabled
6
- * @property {boolean} pause - Pause on breakpoints
7
- * @property {string|undefined} address - Host/port override (optional)
8
- */
9
- /**
10
- * @param {boolean|string} edgeInspect
11
- * @param {boolean|string} edgeInspectBrk
12
- * @returns {InspectSettings}
13
- */
14
- // @ts-expect-error TS(7006) FIXME: Parameter 'edgeInspect' implicitly has an 'any' ty... Remove this comment to see the full error message
15
3
  export const generateInspectSettings = (edgeInspect, edgeInspectBrk) => {
16
4
  const enabled = Boolean(edgeInspect) || Boolean(edgeInspectBrk);
17
5
  const pause = Boolean(edgeInspectBrk);
@@ -29,71 +17,7 @@ export const generateInspectSettings = (edgeInspect, edgeInspectBrk) => {
29
17
  address: getAddress(),
30
18
  };
31
19
  };
32
- /**
33
- *
34
- * @param {object} params
35
- * @param {string=} params.accountId
36
- * @param {*} params.addonsUrls
37
- * @param {import("../lib/blobs/blobs.js").BlobsContext} blobsContext
38
- * @param {import('../commands/types.js').NetlifyOptions["config"]} params.config
39
- * @param {string} [params.configPath] An override for the Netlify config path
40
- * @param {boolean} params.debug
41
- * @param {import('../commands/types.js').NetlifyOptions["cachedConfig"]['env']} params.env
42
- * @param {InspectSettings} params.inspectSettings
43
- * @param {() => Promise<object>} params.getUpdatedConfig
44
- * @param {string} params.geolocationMode
45
- * @param {string} params.geoCountry
46
- * @param {*} params.settings
47
- * @param {boolean} params.offline
48
- * @param {object} params.site
49
- * @param {*} params.siteInfo
50
- * @param {string} params.projectDir
51
- * @param {string} params.repositoryRoot
52
- * @param {import('./state-config.js').default} params.state
53
- * @param {import('../lib/functions/registry.js').FunctionsRegistry=} params.functionsRegistry
54
- * @returns
55
- */
56
- export const startProxyServer = async ({
57
- // @ts-expect-error TS(7031) FIXME: Binding element 'accountId' implicitly has an 'any... Remove this comment to see the full error message
58
- accountId,
59
- // @ts-expect-error TS(7031) FIXME: Binding element 'addonsUrls' implicitly has an 'an... Remove this comment to see the full error message
60
- addonsUrls,
61
- // @ts-expect-error TS(7031) FIXME: Binding element 'blobsContext' implicitly has an '... Remove this comment to see the full error message
62
- blobsContext,
63
- // @ts-expect-error TS(7031) FIXME: Binding element 'accountId' implicitly has an 'any... Remove this comment to see the full error message
64
- command,
65
- // @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
66
- config,
67
- // @ts-expect-error TS(7031) FIXME: Binding element 'configPath' implicitly has an 'an... Remove this comment to see the full error message
68
- configPath,
69
- // @ts-expect-error TS(7031) FIXME: Binding element 'debug' implicitly has an 'any' ty... Remove this comment to see the full error message
70
- debug,
71
- // @ts-expect-error TS(7031) FIXME: Binding element 'env' implicitly has an 'any' type... Remove this comment to see the full error message
72
- env,
73
- // @ts-expect-error TS(7031) FIXME: Binding element 'functionsRegistry' implicitly has... Remove this comment to see the full error message
74
- functionsRegistry,
75
- // @ts-expect-error TS(7031) FIXME: Binding element 'geoCountry' implicitly has an 'an... Remove this comment to see the full error message
76
- geoCountry,
77
- // @ts-expect-error TS(7031) FIXME: Binding element 'geolocationMode' implicitly has a... Remove this comment to see the full error message
78
- geolocationMode,
79
- // @ts-expect-error TS(7031) FIXME: Binding element 'getUpdatedConfig' implicitly has ... Remove this comment to see the full error message
80
- getUpdatedConfig,
81
- // @ts-expect-error TS(7031) FIXME: Binding element 'inspectSettings' implicitly has a... Remove this comment to see the full error message
82
- inspectSettings,
83
- // @ts-expect-error TS(7031) FIXME: Binding element 'offline' implicitly has an 'any' ... Remove this comment to see the full error message
84
- offline,
85
- // @ts-expect-error TS(7031) FIXME: Binding element 'projectDir' implicitly has an 'an... Remove this comment to see the full error message
86
- projectDir,
87
- // @ts-expect-error TS(7031) FIXME: Binding element 'repositoryRoot' implicitly has an... Remove this comment to see the full error message
88
- repositoryRoot,
89
- // @ts-expect-error TS(7031) FIXME: Binding element 'settings' implicitly has an 'any'... Remove this comment to see the full error message
90
- settings,
91
- // @ts-expect-error TS(7031) FIXME: Binding element 'site' implicitly has an 'any' typ... Remove this comment to see the full error message
92
- site,
93
- // @ts-expect-error TS(7031) FIXME: Binding element 'siteInfo' implicitly has an 'any'... Remove this comment to see the full error message
94
- siteInfo,
95
- // @ts-expect-error TS(7031) FIXME: Binding element 'state' implicitly has an 'any' ty... Remove this comment to see the full error message
96
- state, }) => {
20
+ export const startProxyServer = async ({ accountId, addonsUrls, blobsContext, command, config, configPath, debug, env, functionsRegistry, geoCountry, geolocationMode, getUpdatedConfig, inspectSettings, offline, projectDir, repositoryRoot, settings, site, siteInfo, state, }) => {
97
21
  const url = await startProxy({
98
22
  addonsUrls,
99
23
  blobsContext,
@@ -1,27 +1,9 @@
1
- /**
2
- * @param {Pick<import('./types.js').ServerSettings, "https" | "port">} settings
3
- * @returns
4
- */
5
- export declare const getProxyUrl: (settings: any) => string;
1
+ import { BaseCommand } from '../commands/index.js';
2
+ import { $TSFixMe } from '../commands/types.js';
3
+ import { ServerSettings } from './types.js';
4
+ export declare const getProxyUrl: (settings: Pick<ServerSettings, 'https' | 'port'>) => string;
6
5
  export declare const startProxy: ({ accountId, addonsUrls, blobsContext, command, config, configPath, debug, env, functionsRegistry, geoCountry, geolocationMode, getUpdatedConfig, inspectSettings, offline, projectDir, repositoryRoot, settings, siteInfo, state, }: {
7
- accountId: any;
8
- addonsUrls: any;
9
- blobsContext: any;
10
- command: any;
11
- config: any;
12
- configPath: any;
13
- debug: any;
14
- env: any;
15
- functionsRegistry: any;
16
- geoCountry: any;
17
- geolocationMode: any;
18
- getUpdatedConfig: any;
19
- inspectSettings: any;
20
- offline: any;
21
- projectDir: any;
22
- repositoryRoot: any;
23
- settings: any;
24
- siteInfo: any;
25
- state: any;
26
- }) => Promise<string>;
6
+ command: BaseCommand;
7
+ settings: ServerSettings;
8
+ } & Record<string, any>) => Promise<string>;
27
9
  //# sourceMappingURL=proxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/utils/proxy.ts"],"names":[],"mappings":"AAiwBA;;;GAGG;AAEH,eAAO,MAAM,WAAW,2BAGvB,CAAA;AAED,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;qBAmItB,CAAA"}
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/utils/proxy.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAkB/C,OAAO,EAAqB,cAAc,EAAE,MAAM,YAAY,CAAA;AAutB9D,eAAO,MAAM,WAAW,aAAuB,KAAK,cAAc,EAAE,OAAO,GAAG,MAAM,CAAC,WAGpF,CAAA;AAED,eAAO,MAAM,UAAU;aAoBT,WAAW;cAAY,cAAc;2CA2FlD,CAAA"}
@@ -62,7 +62,7 @@ const formatEdgeFunctionError = (errorBuffer, acceptsHtml) => {
62
62
  });
63
63
  };
64
64
  function isInternal(url) {
65
- return url.startsWith('/.netlify/');
65
+ return url?.startsWith('/.netlify/') ?? false;
66
66
  }
67
67
  function isFunction(functionsPort, url) {
68
68
  return functionsPort && url.match(DEFAULT_FUNCTION_URL_EXPRESSION);
@@ -88,15 +88,16 @@ const isExternal = function (match) {
88
88
  const stripOrigin = function ({ hash, pathname, search }) {
89
89
  return `${pathname}${search}${hash}`;
90
90
  };
91
- // @ts-expect-error TS(7031) FIXME: Binding element 'dest' implicitly has an 'any' typ... Remove this comment to see the full error message
92
- const proxyToExternalUrl = function ({ dest, destURL, req, res }) {
93
- console.log(`${NETLIFYDEVLOG} Proxying to ${dest}`);
91
+ const proxyToExternalUrl = function ({ dest, destURL, req, res, }) {
94
92
  const handler = createProxyMiddleware({
95
93
  target: dest.origin,
96
94
  changeOrigin: true,
97
95
  pathRewrite: () => destURL,
96
+ // hide logging
97
+ logLevel: 'warn',
98
98
  ...(Buffer.isBuffer(req.originalBody) && { buffer: toReadableStream(req.originalBody) }),
99
99
  });
100
+ // @ts-expect-error TS(2345) FIXME: Argument of type 'Request' is not assignable to parameter of type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
100
101
  return handler(req, res, () => { });
101
102
  };
102
103
  // @ts-expect-error TS(7031) FIXME: Binding element 'addonUrl' implicitly has an 'any'... Remove this comment to see the full error message
@@ -143,29 +144,16 @@ const alternativePathsFor = function (url) {
143
144
  }
144
145
  return paths;
145
146
  };
146
- const serveRedirect = async function ({
147
- // @ts-expect-error TS(7031) FIXME: Binding element 'env' implicitly has an 'any' type... Remove this comment to see the full error message
148
- env,
149
- // @ts-expect-error TS(7031) FIXME: Binding element 'functionsRegistry' implicitly has... Remove this comment to see the full error message
150
- functionsRegistry,
151
- // @ts-expect-error TS(7031) FIXME: Binding element 'imageProxy' implicitly has an 'an... Remove this comment to see the full error message
152
- imageProxy,
153
- // @ts-expect-error TS(7031) FIXME: Binding element 'match' implicitly has an 'any' ty... Remove this comment to see the full error message
154
- match,
155
- // @ts-expect-error TS(7031) FIXME: Binding element 'options' implicitly has an 'any' ... Remove this comment to see the full error message
156
- options,
157
- // @ts-expect-error TS(7031) FIXME: Binding element 'proxy' implicitly has an 'any' ty... Remove this comment to see the full error message
158
- proxy,
159
- // @ts-expect-error TS(7031) FIXME: Binding element 'req' implicitly has an 'any' type... Remove this comment to see the full error message
160
- req,
161
- // @ts-expect-error TS(7031) FIXME: Binding element 'res' implicitly has an 'any' type... Remove this comment to see the full error message
162
- res,
163
- // @ts-expect-error TS(7031) FIXME: Binding element 'siteInfo' implicitly has an 'any'... Remove this comment to see the full error message
164
- siteInfo, }) {
147
+ const serveRedirect = async function ({ env, functionsRegistry, imageProxy, match, options, proxy, req, res, siteInfo, }) {
165
148
  if (!match)
166
149
  return proxy.web(req, res, options);
167
150
  options = options || req.proxyOptions || {};
168
151
  options.match = null;
152
+ if (match.force404) {
153
+ res.writeHead(404);
154
+ res.end(await render404(options.publicFolder));
155
+ return;
156
+ }
169
157
  if (match.proxyHeaders && Object.keys(match.proxyHeaders).length >= 0) {
170
158
  Object.entries(match.proxyHeaders).forEach(([key, value]) => {
171
159
  req.headers[key] = value;
@@ -195,9 +183,7 @@ siteInfo, }) {
195
183
  const originalURL = req.url;
196
184
  if (match.exceptions && match.exceptions.JWT) {
197
185
  // Some values of JWT can start with :, so, make sure to normalize them
198
- const expectedRoles = new Set(
199
- // @ts-expect-error TS(7006) FIXME: Parameter 'value' implicitly has an 'any' type.
200
- match.exceptions.JWT.split(',').map((value) => (value.startsWith(':') ? value.slice(1) : value)));
186
+ const expectedRoles = new Set(match.exceptions.JWT.split(',').map((value) => (value.startsWith(':') ? value.slice(1) : value)));
201
187
  const cookieValues = cookie.parse(req.headers.cookie || '');
202
188
  const token = cookieValues.nf_jwt;
203
189
  // Serve not found by default
@@ -243,11 +229,6 @@ siteInfo, }) {
243
229
  return proxy.web(req, res, { ...options, staticFile });
244
230
  }
245
231
  }
246
- if (match.force404) {
247
- res.writeHead(404);
248
- res.end(await render404(options.publicFolder));
249
- return;
250
- }
251
232
  if (match.force || !staticFile || !options.framework || req.method === 'POST') {
252
233
  // construct destination URL from redirect rule match
253
234
  const dest = new URL(match.to, `${reqUrl.protocol}//${reqUrl.host}`);
@@ -269,6 +250,11 @@ siteInfo, }) {
269
250
  destURL = `${dest}`;
270
251
  }
271
252
  else {
253
+ const isHiddenProxy = match.proxyHeaders &&
254
+ Object.entries(match.proxyHeaders).some(([key, val]) => key.toLowerCase() === 'x-nf-hidden-proxy' && val === 'true');
255
+ if (!isHiddenProxy) {
256
+ console.log(`${NETLIFYDEVLOG} Proxying to ${dest}`);
257
+ }
272
258
  return proxyToExternalUrl({ req, res, dest, destURL });
273
259
  }
274
260
  }
@@ -539,34 +525,9 @@ siteInfo, }) {
539
525
  };
540
526
  return handlers;
541
527
  };
542
- const onRequest = async ({
543
- // @ts-expect-error TS(7031) FIXME: Binding element 'addonsUrls' implicitly has an 'an... Remove this comment to see the full error message
544
- addonsUrls,
545
- // @ts-expect-error TS(7031) FIXME: Binding element 'edgeFunctionsProxy' implicitly ha... Remove this comment to see the full error message
546
- edgeFunctionsProxy,
547
- // @ts-expect-error TS(7031) FIXME: Binding element 'env' implicitly has an 'any' type... Remove this comment to see the full error message
548
- env,
549
- // @ts-expect-error TS(7031) FIXME: Binding element 'functionsRegistry' implicitly has... Remove this comment to see the full error message
550
- functionsRegistry,
551
- // @ts-expect-error TS(7031) FIXME: Binding element 'functionsServer' implicitly has a... Remove this comment to see the full error message
552
- functionsServer,
553
- // @ts-expect-error TS(7031) FIXME: Binding element 'imageProxy' implicitly has an 'an... Remove this comment to see the full error message
554
- imageProxy,
555
- // @ts-expect-error TS(7031) FIXME: Binding element 'proxy' implicitly has an 'any' ty... Remove this comment to see the full error message
556
- proxy,
557
- // @ts-expect-error TS(7031) FIXME: Binding element 'rewriter' implicitly has an 'any'... Remove this comment to see the full error message
558
- rewriter,
559
- // @ts-expect-error TS(7031) FIXME: Binding element 'settings' implicitly has an 'any'... Remove this comment to see the full error message
560
- settings,
561
- // @ts-expect-error TS(7031) FIXME: Binding element 'siteInfo' implicitly has an 'any'... Remove this comment to see the full error message
562
- siteInfo, },
563
- // @ts-expect-error TS(7006) FIXME: Parameter 'req' implicitly has an 'any' type.
564
- req,
565
- // @ts-expect-error TS(7006) FIXME: Parameter 'res' implicitly has an 'any' type.
566
- res) => {
567
- req.originalBody = ['GET', 'OPTIONS', 'HEAD'].includes(req.method)
568
- ? null
569
- : await createStreamPromise(req, BYTES_LIMIT);
528
+ const onRequest = async ({ addonsUrls, edgeFunctionsProxy, env, functionsRegistry, functionsServer, imageProxy, proxy, rewriter, settings, siteInfo, }, req, res) => {
529
+ req.originalBody =
530
+ req.method && ['GET', 'OPTIONS', 'HEAD'].includes(req.method) ? null : await createStreamPromise(req, BYTES_LIMIT);
570
531
  if (isImageRequest(req)) {
571
532
  return imageProxy(req, res);
572
533
  }
@@ -575,7 +536,7 @@ res) => {
575
536
  return proxy.web(req, res, { target: edgeFunctionsProxyURL });
576
537
  }
577
538
  const functionMatch = functionsRegistry &&
578
- (await functionsRegistry.getFunctionForURLPath(req.url, req.method, () => getStatic(decodeURIComponent(reqToURL(req, req.url).pathname), settings.dist)));
539
+ (await functionsRegistry.getFunctionForURLPath(req.url, req.method, () => getStatic(decodeURIComponent(reqToURL(req, req.url).pathname), settings.dist ?? '')));
579
540
  if (functionMatch) {
580
541
  // Setting an internal header with the function name so that we don't
581
542
  // have to match the URL again in the functions server.
@@ -599,7 +560,7 @@ res) => {
599
560
  const options = {
600
561
  match,
601
562
  addonsUrls,
602
- target: `http://${isIPv6(settings.frameworkHost) ? `[${settings.frameworkHost}]` : settings.frameworkHost}:${settings.frameworkPort}`,
563
+ target: `http://${settings.frameworkHost && isIPv6(settings.frameworkHost) ? `[${settings.frameworkHost}]` : settings.frameworkHost}:${settings.frameworkPort}`,
603
564
  publicFolder: settings.dist,
604
565
  functionsServer,
605
566
  functionsPort: settings.functionsPort,
@@ -628,54 +589,11 @@ res) => {
628
589
  }
629
590
  proxy.web(req, res, options);
630
591
  };
631
- /**
632
- * @param {Pick<import('./types.js').ServerSettings, "https" | "port">} settings
633
- * @returns
634
- */
635
- // @ts-expect-error TS(7006) FIXME: Parameter 'settings' implicitly has an 'any' type.
636
592
  export const getProxyUrl = function (settings) {
637
593
  const scheme = settings.https ? 'https' : 'http';
638
594
  return `${scheme}://localhost:${settings.port}`;
639
595
  };
640
- export const startProxy = async function ({
641
- // @ts-expect-error TS(7031) FIXME: Binding element 'accountId' implicitly has an 'any... Remove this comment to see the full error message
642
- accountId,
643
- // @ts-expect-error TS(7031) FIXME: Binding element 'addonsUrls' implicitly has an 'an... Remove this comment to see the full error message
644
- addonsUrls,
645
- // @ts-expect-error TS(7031) FIXME: Binding element 'blobsContext' implicitly has an '... Remove this comment to see the full error message
646
- blobsContext,
647
- // @ts-expect-error TS(7031) FIXME: Binding element 'accountId' implicitly has an 'any... Remove this comment to see the full error message
648
- command,
649
- // @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
650
- config,
651
- // @ts-expect-error TS(7031) FIXME: Binding element 'configPath' implicitly has an 'an... Remove this comment to see the full error message
652
- configPath,
653
- // @ts-expect-error TS(7031) FIXME: Binding element 'debug' implicitly has an 'any' ty... Remove this comment to see the full error message
654
- debug,
655
- // @ts-expect-error TS(7031) FIXME: Binding element 'env' implicitly has an 'any' type... Remove this comment to see the full error message
656
- env,
657
- // @ts-expect-error TS(7031) FIXME: Binding element 'functionsRegistry' implicitly has... Remove this comment to see the full error message
658
- functionsRegistry,
659
- // @ts-expect-error TS(7031) FIXME: Binding element 'geoCountry' implicitly has an 'an... Remove this comment to see the full error message
660
- geoCountry,
661
- // @ts-expect-error TS(7031) FIXME: Binding element 'geolocationMode' implicitly has a... Remove this comment to see the full error message
662
- geolocationMode,
663
- // @ts-expect-error TS(7031) FIXME: Binding element 'getUpdatedConfig' implicitly has ... Remove this comment to see the full error message
664
- getUpdatedConfig,
665
- // @ts-expect-error TS(7031) FIXME: Binding element 'inspectSettings' implicitly has a... Remove this comment to see the full error message
666
- inspectSettings,
667
- // @ts-expect-error TS(7031) FIXME: Binding element 'offline' implicitly has an 'any' ... Remove this comment to see the full error message
668
- offline,
669
- // @ts-expect-error TS(7031) FIXME: Binding element 'projectDir' implicitly has an 'an... Remove this comment to see the full error message
670
- projectDir,
671
- // @ts-expect-error TS(7031) FIXME: Binding element 'repositoryRoot' implicitly has an... Remove this comment to see the full error message
672
- repositoryRoot,
673
- // @ts-expect-error TS(7031) FIXME: Binding element 'settings' implicitly has an 'any'... Remove this comment to see the full error message
674
- settings,
675
- // @ts-expect-error TS(7031) FIXME: Binding element 'siteInfo' implicitly has an 'any'... Remove this comment to see the full error message
676
- siteInfo,
677
- // @ts-expect-error TS(7031) FIXME: Binding element 'state' implicitly has an 'any' ty... Remove this comment to see the full error message
678
- state, }) {
596
+ export const startProxy = async function ({ accountId, addonsUrls, blobsContext, command, config, configPath, debug, env, functionsRegistry, geoCountry, geolocationMode, getUpdatedConfig, inspectSettings, offline, projectDir, repositoryRoot, settings, siteInfo, state, }) {
679
597
  const secondaryServerPort = settings.https ? await getAvailablePort() : null;
680
598
  const functionsServer = settings.functionsPort ? `http://127.0.0.1:${settings.functionsPort}` : null;
681
599
  const edgeFunctionsProxy = await initializeEdgeFunctionsProxy({
@@ -738,7 +656,6 @@ state, }) {
738
656
  const primaryServer = settings.https
739
657
  ? https.createServer({ cert: settings.https.cert, key: settings.https.key }, onRequestWithOptions)
740
658
  : http.createServer(onRequestWithOptions);
741
- // @ts-expect-error TS(7006) FIXME: Parameter 'req' implicitly has an 'any' type.
742
659
  const onUpgrade = function onUpgrade(req, socket, head) {
743
660
  proxy.ws(req, socket, head);
744
661
  };
@@ -1,3 +1,4 @@
1
+ import { Rewriter } from './types.js';
1
2
  export declare const onChanges: (files: any, listener: any) => void;
2
3
  export declare const getWatchers: () => any[];
3
4
  export declare const getLanguage: (headers: any) => any;
@@ -9,5 +10,5 @@ export declare const createRewriter: ({ config, configPath, distDir, geoCountry,
9
10
  jwtRoleClaim: any;
10
11
  jwtSecret: any;
11
12
  projectDir: any;
12
- }) => Promise<(req: any) => Promise<any>>;
13
+ }) => Promise<Rewriter>;
13
14
  //# sourceMappingURL=rules-proxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rules-proxy.d.ts","sourceRoot":"","sources":["../../src/utils/rules-proxy.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,SAAS,qCAQrB,CAAA;AAED,eAAO,MAAM,WAAW,aAGvB,CAAA;AAGD,eAAO,MAAM,WAAW,uBAKvB,CAAA;AAED,eAAO,MAAM,cAAc;;;;;;;;yCAiF1B,CAAA"}
1
+ {"version":3,"file":"rules-proxy.d.ts","sourceRoot":"","sources":["../../src/utils/rules-proxy.ts"],"names":[],"mappings":"AAaA,OAAO,EAAW,QAAQ,EAAE,MAAM,YAAY,CAAA;AAM9C,eAAO,MAAM,SAAS,qCAQrB,CAAA;AAED,eAAO,MAAM,WAAW,aAGvB,CAAA;AAGD,eAAO,MAAM,WAAW,uBAKvB,CAAA;AAED,eAAO,MAAM,cAAc;;;;;;;;MAevB,QAAQ,QAAQ,CAoEnB,CAAA"}
@@ -2,7 +2,6 @@ import path from 'path';
2
2
  import chokidar from 'chokidar';
3
3
  // @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'cook... Remove this comment to see the full error message
4
4
  import cookie from 'cookie';
5
- // @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'netl... Remove this comment to see the full error message
6
5
  import redirector from 'netlify-redirector';
7
6
  import pFilter from 'p-filter';
8
7
  import { fileExistsAsync } from '../lib/fs.js';
@@ -46,7 +45,6 @@ jwtRoleClaim,
46
45
  jwtSecret,
47
46
  // @ts-expect-error TS(7031) FIXME: Binding element 'projectDir' implicitly has an 'an... Remove this comment to see the full error message
48
47
  projectDir, }) {
49
- // @ts-expect-error TS(7034) FIXME: Variable 'matcher' implicitly has type 'any' in so... Remove this comment to see the full error message
50
48
  let matcher = null;
51
49
  const redirectsFiles = [...new Set([path.resolve(distDir, '_redirects'), path.resolve(projectDir, '_redirects')])];
52
50
  let redirects = await parseRedirects({ config, redirectsFiles, configPath });
@@ -58,7 +56,6 @@ projectDir, }) {
58
56
  matcher = null;
59
57
  });
60
58
  const getMatcher = async () => {
61
- // @ts-expect-error TS(7005) FIXME: Variable 'matcher' implicitly has an 'any' type.
62
59
  if (matcher)
63
60
  return matcher;
64
61
  if (redirects.length !== 0) {
@@ -76,7 +73,7 @@ projectDir, }) {
76
73
  // @ts-expect-error TS(7006) FIXME: Parameter 'req' implicitly has an 'any' type.
77
74
  return async function rewriter(req) {
78
75
  const matcherFunc = await getMatcher();
79
- const reqUrl = new URL(req.url, `${req.protocol || (req.headers.scheme && `${req.headers.scheme}:`) || 'http:'}//${req.hostname || req.headers.host}`);
76
+ const reqUrl = new URL(req.url ?? '', `${req.protocol || (req.headers.scheme && `${req.headers.scheme}:`) || 'http:'}//${req.hostname || req.headers.host}`);
80
77
  const cookieValues = cookie.parse(req.headers.cookie || '');
81
78
  const headers = {
82
79
  'x-language': cookieValues.nf_lang || getLanguage(req.headers),
@@ -91,9 +88,13 @@ projectDir, }) {
91
88
  query: reqUrl.search.slice(1),
92
89
  headers,
93
90
  cookieValues,
94
- // @ts-expect-error TS(7006) FIXME: Parameter 'name' implicitly has an 'any' type.
95
- getHeader: (name) => headers[name.toLowerCase()] || '',
96
- // @ts-expect-error TS(7006) FIXME: Parameter 'key' implicitly has an 'any' type.
91
+ getHeader: (name) => {
92
+ const val = headers[name.toLowerCase()];
93
+ if (Array.isArray(val)) {
94
+ return val[0];
95
+ }
96
+ return val || '';
97
+ },
97
98
  getCookie: (key) => cookieValues[key] || '',
98
99
  };
99
100
  const match = matcherFunc.match(matchReq);
@@ -1,19 +1,17 @@
1
- /**
2
- * @param {object} params
3
- * @param {import('../commands/base-command.js').default} params.command
4
- * @param {import('../commands/base-command.js').default} params.command
5
- * @param {*} params.options The flags of the command
6
- * @param {import('./types.js').ServerSettings} params.settings
7
- * @param {NodeJS.ProcessEnv} [params.env]
8
- * @param {'build' | 'dev'} [params.timeline]
9
- * @returns
10
- */
11
- export declare const runNetlifyBuild: ({ command, env, options, settings, timeline }: {
12
- command: any;
13
- env?: {} | undefined;
14
- options: any;
15
- settings: any;
16
- timeline?: string | undefined;
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ /// <reference types="node" resolution-mode="require"/>
4
+ /// <reference types="node" resolution-mode="require"/>
5
+ /// <reference types="node" resolution-mode="require"/>
6
+ import BaseCommand from '../commands/base-command.js';
7
+ import { $TSFixMe } from '../commands/types.js';
8
+ import { ServerSettings } from './types.js';
9
+ export declare const runNetlifyBuild: ({ command, env, options, settings, timeline, }: {
10
+ command: BaseCommand;
11
+ options: $TSFixMe;
12
+ settings: ServerSettings;
13
+ env: NodeJS.ProcessEnv;
14
+ timeline: 'build' | 'dev';
17
15
  }) => Promise<{
18
16
  configPath?: undefined;
19
17
  configMutations?: undefined;
@@ -24,10 +22,7 @@ export declare const runNetlifyBuild: ({ command, env, options, settings, timeli
24
22
  configMutations: any;
25
23
  configPath?: undefined;
26
24
  }>;
27
- /**
28
- * @param {Omit<Parameters<typeof runNetlifyBuild>[0], 'timeline'>} options
29
- */
30
- export declare const runDevTimeline: (options: any) => Promise<{
25
+ export declare const runDevTimeline: (options: Omit<Parameters<typeof runNetlifyBuild>[0], 'timeline'>) => Promise<{
31
26
  configPath?: undefined;
32
27
  configMutations?: undefined;
33
28
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"run-build.d.ts","sourceRoot":"","sources":["../../src/utils/run-build.ts"],"names":[],"mappings":"AA+CA;;;;;;;;;GASG;AAEH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;EAoG3B,CAAA;AAED;;GAEG;AAEH,eAAO,MAAM,cAAc;;;;;;;;;EAAgE,CAAA;AAE3F;;GAEG;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;EAAkE,CAAA"}
1
+ {"version":3,"file":"run-build.d.ts","sourceRoot":"","sources":["../../src/utils/run-build.ts"],"names":[],"mappings":";;;;;AAGA,OAAO,WAAW,MAAM,6BAA6B,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAS/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAqC3C,eAAO,MAAM,eAAe;aAOjB,WAAW;aAEX,QAAQ;cACP,cAAc;SACnB,OAAO,UAAU;cACZ,OAAO,GAAG,KAAK;;;;;;;;;;EAqG1B,CAAA;AAED,eAAO,MAAM,cAAc,YAAa,KAAK,WAAW,sBAAsB,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;;;;;;;;;EAC7C,CAAA;AAElD;;GAEG;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;EAAkE,CAAA"}