netlify-cli 18.0.0 → 18.0.1-rc.1

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 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/utils/proxy.ts"],"names":[],"mappings":"AA6BA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAkB,MAAM,sBAAsB,CAAA;AAkB/D,OAAO,EAAqB,cAAc,EAAE,MAAM,YAAY,CAAA;AAqxB9D,eAAO,MAAM,WAAW,aAAuB,KAAK,cAAc,EAAE,OAAO,GAAG,MAAM,CAAC,WAGpF,CAAA;AAID,eAAO,MAAM,UAAU;aAsBT,WAAW;cAAY,cAAc;0BAAwB,OAAO;2CA4GjF,CAAA"}
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/utils/proxy.ts"],"names":[],"mappings":"AA6BA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAkB,MAAM,sBAAsB,CAAA;AAkB/D,OAAO,EAAqB,cAAc,EAAE,MAAM,YAAY,CAAA;AAmyB9D,eAAO,MAAM,WAAW,aAAuB,KAAK,cAAc,EAAE,OAAO,GAAG,MAAM,CAAC,WAGpF,CAAA;AAID,eAAO,MAAM,UAAU;aAsBT,WAAW;cAAY,cAAc;0BAAwB,OAAO;2CA4GjF,CAAA"}
@@ -114,6 +114,16 @@ const getStatic = async function (pathname, publicFolder) {
114
114
  }
115
115
  return `/${path.relative(publicFolder, file)}`;
116
116
  };
117
+ const isEndpointExists = async function (endpoint, origin) {
118
+ const url = new URL(endpoint, origin);
119
+ try {
120
+ const res = await fetch(url, { method: 'HEAD' });
121
+ return res.status !== 404;
122
+ }
123
+ catch (e) {
124
+ return false;
125
+ }
126
+ };
117
127
  // @ts-expect-error TS(7006) FIXME: Parameter 'match' implicitly has an 'any' type.
118
128
  const isExternal = function (match) {
119
129
  return match.to && match.to.match(/^https?:\/\//);
@@ -261,8 +271,10 @@ const serveRedirect = async function ({ env, functionsRegistry, imageProxy, matc
261
271
  }
262
272
  const reqUrl = reqToURL(req, req.url);
263
273
  const staticFile = await getStatic(decodeURIComponent(reqUrl.pathname), options.publicFolder);
264
- if (staticFile) {
265
- req.url = encodeURI(staticFile) + reqUrl.search;
274
+ const endpointExists = !staticFile && (await isEndpointExists(decodeURIComponent(reqUrl.pathname), options.target));
275
+ if (staticFile || endpointExists) {
276
+ const pathname = staticFile || reqUrl.pathname;
277
+ req.url = encodeURI(pathname) + reqUrl.search;
266
278
  // if there is an existing static file and it is not a forced redirect, return the file
267
279
  if (!match.force) {
268
280
  return proxy.web(req, res, { ...options, staticFile });
@@ -533,10 +545,12 @@ const initializeProxy = async function ({ config, configPath, distDir, env, host
533
545
  let proxyResHeaders = proxyRes.headers;
534
546
  if (htmlInjections) {
535
547
  responseBody = await injectHtml(responseBody, proxyRes, htmlInjections);
536
- proxyResHeaders = {
537
- ...proxyResHeaders,
538
- 'content-length': String(responseBody.byteLength),
539
- };
548
+ if (!proxyResHeaders['transfer-encoding']) {
549
+ proxyResHeaders = {
550
+ ...proxyResHeaders,
551
+ 'content-length': String(responseBody.byteLength),
552
+ };
553
+ }
540
554
  }
541
555
  res.writeHead(responseStatus, proxyResHeaders);
542
556
  if (responseStatus !== 304) {