netlify-cli 18.0.0 → 18.0.1-rc.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.
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/proxy.d.ts.map +1 -1
- package/dist/utils/proxy.js +14 -2
- package/npm-shrinkwrap.json +183 -357
- package/package.json +7 -7
|
@@ -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;
|
|
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;AAiyB9D,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"}
|
package/dist/utils/proxy.js
CHANGED
|
@@ -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
|
-
|
|
265
|
-
|
|
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 });
|