vite-plugin-vercel 11.0.0-beta.16 → 11.0.0-beta.17
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/vite.js +50 -2
- package/package.json +1 -1
package/dist/vite.js
CHANGED
|
@@ -543,6 +543,30 @@ function getVcConfig(pluginConfig, filename, options) {
|
|
|
543
543
|
});
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region src/utils/request.ts
|
|
548
|
+
function getOriginalRequest(request) {
|
|
549
|
+
const xNowRouteMatchesHeader = request.headers.get("x-now-route-matches");
|
|
550
|
+
let newUrl = null;
|
|
551
|
+
let newRequest = request;
|
|
552
|
+
if (typeof xNowRouteMatchesHeader === "string") {
|
|
553
|
+
const originalPathBis = new URLSearchParams(xNowRouteMatchesHeader).get("1");
|
|
554
|
+
if (originalPathBis) newUrl = new URL(originalPathBis, request.url).toString();
|
|
555
|
+
}
|
|
556
|
+
if (newUrl) newRequest = new Request(newUrl, {
|
|
557
|
+
method: request.method,
|
|
558
|
+
headers: request.headers,
|
|
559
|
+
body: request.body,
|
|
560
|
+
mode: request.mode,
|
|
561
|
+
credentials: request.credentials,
|
|
562
|
+
cache: request.cache,
|
|
563
|
+
redirect: request.redirect,
|
|
564
|
+
referrer: request.referrer,
|
|
565
|
+
integrity: request.integrity
|
|
566
|
+
});
|
|
567
|
+
return newRequest;
|
|
568
|
+
}
|
|
569
|
+
|
|
546
570
|
//#endregion
|
|
547
571
|
//#region src/plugins/loader.ts
|
|
548
572
|
const re_DUMMY = new RegExp(`__DUMMY__$`);
|
|
@@ -584,8 +608,15 @@ function loaderPlugin(pluginConfig) {
|
|
|
584
608
|
async handler(id) {
|
|
585
609
|
const mod = id.replace(re_edge, "");
|
|
586
610
|
return `import mod from ${JSON.stringify(mod)};
|
|
587
|
-
|
|
588
|
-
|
|
611
|
+
|
|
612
|
+
${getOriginalRequest.toString()}
|
|
613
|
+
|
|
614
|
+
const fn = (...args) => {
|
|
615
|
+
Object.assign(args[0], getOriginalRequest(request));
|
|
616
|
+
return mod.fetch(...args);
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
export default fn`;
|
|
589
620
|
}
|
|
590
621
|
}
|
|
591
622
|
},
|
|
@@ -605,7 +636,19 @@ export default def;`;
|
|
|
605
636
|
async handler(id) {
|
|
606
637
|
const mod = id.replace(re_node, "");
|
|
607
638
|
return `import mod from ${JSON.stringify(mod)};
|
|
639
|
+
|
|
640
|
+
${getOriginalRequest.toString()}
|
|
641
|
+
|
|
642
|
+
if (mod?.fetch) {
|
|
643
|
+
const ori = mod.fetch;
|
|
644
|
+
mod.fetch = (...args) => {
|
|
645
|
+
Object.assign(args[0], getOriginalRequest(request));
|
|
646
|
+
return ori(...args);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
608
650
|
const def = mod?.server?.nodeHandler ?? mod;
|
|
651
|
+
|
|
609
652
|
export default def;`;
|
|
610
653
|
}
|
|
611
654
|
}
|
|
@@ -745,6 +788,7 @@ function getConfig(pluginConfig) {
|
|
|
745
788
|
routes: buildRoutes
|
|
746
789
|
}]
|
|
747
790
|
});
|
|
791
|
+
for (const route of cleanRoutes) wrapRouteInParentheses(route);
|
|
748
792
|
return vercelOutputConfigSchema.parse({
|
|
749
793
|
version: 3,
|
|
750
794
|
...pluginConfig.config,
|
|
@@ -752,6 +796,10 @@ function getConfig(pluginConfig) {
|
|
|
752
796
|
overrides: { ...pluginConfig.config?.overrides }
|
|
753
797
|
});
|
|
754
798
|
}
|
|
799
|
+
function wrapRouteInParentheses(route) {
|
|
800
|
+
if (!route.dest || route.dest.match(/^\(.*\)$/) || route.dest.match(/^\^\(.*\)\$$/)) return;
|
|
801
|
+
route.dest = `(${route.dest})`;
|
|
802
|
+
}
|
|
755
803
|
|
|
756
804
|
//#endregion
|
|
757
805
|
//#region src/utils/const.ts
|