feat: init
This commit is contained in:
36
node_modules/nitropack/dist/presets/vercel/runtime/vercel.mjs
generated
vendored
Normal file
36
node_modules/nitropack/dist/presets/vercel/runtime/vercel.mjs
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import "#nitro-internal-pollyfills";
|
||||
import { useNitroApp } from "nitropack/runtime";
|
||||
import { getRouteRulesForPath } from "nitropack/runtime/internal/index";
|
||||
import { toNodeListener } from "h3";
|
||||
import { parseQuery, withQuery } from "ufo";
|
||||
import { ISR_URL_PARAM } from "./consts.mjs";
|
||||
const nitroApp = useNitroApp();
|
||||
const handler = toNodeListener(nitroApp.h3App);
|
||||
const listener = function(req, res) {
|
||||
const isrRoute = req.headers["x-now-route-matches"];
|
||||
if (isrRoute) {
|
||||
const { [ISR_URL_PARAM]: url } = parseQuery(isrRoute);
|
||||
if (url && typeof url === "string") {
|
||||
const routeRules = getRouteRulesForPath(url);
|
||||
if (routeRules.isr) {
|
||||
req.url = url;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const queryIndex = req.url.indexOf("?");
|
||||
const urlQueryIndex = queryIndex === -1 ? -1 : req.url.indexOf(`${ISR_URL_PARAM}=`, queryIndex);
|
||||
if (urlQueryIndex !== -1) {
|
||||
const { [ISR_URL_PARAM]: url, ...params } = parseQuery(
|
||||
req.url.slice(queryIndex)
|
||||
);
|
||||
if (url && typeof url === "string") {
|
||||
const routeRules = getRouteRulesForPath(url);
|
||||
if (routeRules.isr) {
|
||||
req.url = withQuery(url, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return handler(req, res);
|
||||
};
|
||||
export default listener;
|
||||
Reference in New Issue
Block a user