@tanstack/start-server-core 1.120.4-alpha.8 → 1.120.4
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/README.md +27 -6
- package/dist/cjs/createRequestHandler.cjs +3 -1
- package/dist/cjs/createRequestHandler.cjs.map +1 -1
- package/dist/cjs/createStartHandler.cjs +30 -235
- package/dist/cjs/createStartHandler.cjs.map +1 -1
- package/dist/cjs/createStartHandler.d.cts +6 -8
- package/dist/cjs/h3.cjs +73 -30
- package/dist/cjs/h3.cjs.map +1 -1
- package/dist/cjs/h3.d.cts +7 -11
- package/dist/cjs/handlerCallback.cjs.map +1 -1
- package/dist/cjs/handlerCallback.d.cts +4 -3
- package/dist/cjs/index.cjs +14 -20
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -7
- package/dist/esm/createRequestHandler.js +3 -1
- package/dist/esm/createRequestHandler.js.map +1 -1
- package/dist/esm/createStartHandler.d.ts +6 -8
- package/dist/esm/createStartHandler.js +32 -215
- package/dist/esm/createStartHandler.js.map +1 -1
- package/dist/esm/h3.d.ts +7 -11
- package/dist/esm/h3.js +63 -26
- package/dist/esm/h3.js.map +1 -1
- package/dist/esm/handlerCallback.d.ts +4 -3
- package/dist/esm/handlerCallback.js.map +1 -1
- package/dist/esm/index.d.ts +1 -7
- package/dist/esm/index.js +5 -17
- package/dist/esm/index.js.map +1 -1
- package/package.json +6 -9
- package/src/createRequestHandler.ts +3 -1
- package/src/createStartHandler.ts +48 -325
- package/src/h3.ts +78 -71
- package/src/handlerCallback.ts +12 -5
- package/src/index.tsx +1 -13
- package/dist/cjs/router-manifest.cjs +0 -44
- package/dist/cjs/router-manifest.cjs.map +0 -1
- package/dist/cjs/router-manifest.d.cts +0 -17
- package/dist/cjs/server-functions-handler.cjs +0 -154
- package/dist/cjs/server-functions-handler.cjs.map +0 -1
- package/dist/cjs/server-functions-handler.d.cts +0 -4
- package/dist/cjs/serverRoute.cjs +0 -100
- package/dist/cjs/serverRoute.cjs.map +0 -1
- package/dist/cjs/serverRoute.d.cts +0 -115
- package/dist/cjs/undici.cjs +0 -14
- package/dist/cjs/undici.cjs.map +0 -1
- package/dist/cjs/undici.d.cts +0 -43
- package/dist/esm/router-manifest.d.ts +0 -17
- package/dist/esm/router-manifest.js +0 -44
- package/dist/esm/router-manifest.js.map +0 -1
- package/dist/esm/server-functions-handler.d.ts +0 -4
- package/dist/esm/server-functions-handler.js +0 -154
- package/dist/esm/server-functions-handler.js.map +0 -1
- package/dist/esm/serverRoute.d.ts +0 -115
- package/dist/esm/serverRoute.js +0 -100
- package/dist/esm/serverRoute.js.map +0 -1
- package/dist/esm/undici.d.ts +0 -43
- package/dist/esm/undici.js +0 -14
- package/dist/esm/undici.js.map +0 -1
- package/src/router-manifest.ts +0 -79
- package/src/server-functions-handler.ts +0 -273
- package/src/serverRoute.ts +0 -661
- package/src/tanstack-start.d.ts +0 -5
- package/src/undici.ts +0 -60
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { tsrStartManifest } from "tanstack:start-manifest";
|
|
2
|
-
import { rootRouteId } from "@tanstack/router-core";
|
|
3
|
-
function getStartManifest() {
|
|
4
|
-
const startManifest = tsrStartManifest();
|
|
5
|
-
const rootRoute = startManifest.routes[rootRouteId] = startManifest.routes[rootRouteId] || {};
|
|
6
|
-
rootRoute.assets = rootRoute.assets || [];
|
|
7
|
-
if (process.env.NODE_ENV === "development" && !process.env.TSS_CLIENT_ENTRY) {
|
|
8
|
-
throw new Error(
|
|
9
|
-
"tanstack/start-server-core: TSS_CLIENT_ENTRY must be defined in your environment for getStartManifest()"
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
if (process.env.NODE_ENV === "development") {
|
|
13
|
-
const script = `${globalThis.TSS_INJECTED_HEAD_SCRIPTS ? globalThis.TSS_INJECTED_HEAD_SCRIPTS + "; " : ""}import(${JSON.stringify(process.env.TSS_CLIENT_ENTRY)})`;
|
|
14
|
-
rootRoute.assets.push({
|
|
15
|
-
tag: "script",
|
|
16
|
-
attrs: {
|
|
17
|
-
type: "module",
|
|
18
|
-
suppressHydrationWarning: true,
|
|
19
|
-
async: true
|
|
20
|
-
},
|
|
21
|
-
children: script
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
const manifest = {
|
|
25
|
-
...startManifest,
|
|
26
|
-
routes: Object.fromEntries(
|
|
27
|
-
Object.entries(startManifest.routes).map(([k, v]) => {
|
|
28
|
-
const { preloads, assets } = v;
|
|
29
|
-
return [
|
|
30
|
-
k,
|
|
31
|
-
{
|
|
32
|
-
preloads,
|
|
33
|
-
assets
|
|
34
|
-
}
|
|
35
|
-
];
|
|
36
|
-
})
|
|
37
|
-
)
|
|
38
|
-
};
|
|
39
|
-
return manifest;
|
|
40
|
-
}
|
|
41
|
-
export {
|
|
42
|
-
getStartManifest
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=router-manifest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router-manifest.js","sources":["../../src/router-manifest.ts"],"sourcesContent":["import { tsrStartManifest } from 'tanstack:start-manifest'\nimport { rootRouteId } from '@tanstack/router-core'\n\ndeclare global {\n // eslint-disable-next-line no-var\n var TSS_INJECTED_HEAD_SCRIPTS: string | undefined\n}\n\n/**\n * @description Returns the router manifest that should be sent to the client.\n * This includes only the assets and preloads for the current route and any\n * special assets that are needed for the client. It does not include relationships\n * between routes or any other data that is not needed for the client.\n */\nexport function getStartManifest() {\n const startManifest = tsrStartManifest()\n\n const rootRoute = (startManifest.routes[rootRouteId] =\n startManifest.routes[rootRouteId] || {})\n\n rootRoute.assets = rootRoute.assets || []\n\n // Get the entry for the client\n // const ClientManifest = getManifest('client')\n\n // const importPath =\n // ClientManifest.inputs[ClientManifest.handler]?.output.path\n // if (!importPath) {\n // invariant(importPath, 'Could not find client entry in manifest')\n // }\n\n if (process.env.NODE_ENV === 'development' && !process.env.TSS_CLIENT_ENTRY) {\n throw new Error(\n 'tanstack/start-server-core: TSS_CLIENT_ENTRY must be defined in your environment for getStartManifest()',\n )\n }\n\n if (process.env.NODE_ENV === 'development') {\n // Always fake that HMR is ready\n // const CLIENT_BASE = sanitizeBase(process.env.TSS_CLIENT_BASE || '')\n\n // if (!CLIENT_BASE) {\n // throw new Error(\n // 'tanstack/start-router-manifest: TSS_CLIENT_BASE must be defined in your environment for getFullRouterManifest()',\n // )\n // }\n\n const script = `${globalThis.TSS_INJECTED_HEAD_SCRIPTS ? globalThis.TSS_INJECTED_HEAD_SCRIPTS + '; ' : ''}import(${JSON.stringify(process.env.TSS_CLIENT_ENTRY)})`\n\n rootRoute.assets.push({\n tag: 'script',\n attrs: {\n type: 'module',\n suppressHydrationWarning: true,\n async: true,\n },\n children: script,\n })\n }\n\n const manifest = {\n ...startManifest,\n routes: Object.fromEntries(\n Object.entries(startManifest.routes).map(([k, v]) => {\n const { preloads, assets } = v\n return [\n k,\n {\n preloads,\n assets,\n },\n ]\n }),\n ),\n }\n\n // Strip out anything that isn't needed for the client\n return manifest\n}\n"],"names":[],"mappings":";;AAcO,SAAS,mBAAmB;AACjC,QAAM,gBAAgB,iBAAiB;AAEjC,QAAA,YAAa,cAAc,OAAO,WAAW,IACjD,cAAc,OAAO,WAAW,KAAK,CAAC;AAE9B,YAAA,SAAS,UAAU,UAAU,CAAC;AAWxC,MAAI,QAAQ,IAAI,aAAa,iBAAiB,CAAC,QAAQ,IAAI,kBAAkB;AAC3E,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAGE,MAAA,QAAQ,IAAI,aAAa,eAAe;AAU1C,UAAM,SAAS,GAAG,WAAW,4BAA4B,WAAW,4BAA4B,OAAO,EAAE,UAAU,KAAK,UAAU,QAAQ,IAAI,gBAAgB,CAAC;AAE/J,cAAU,OAAO,KAAK;AAAA,MACpB,KAAK;AAAA,MACL,OAAO;AAAA,QACL,MAAM;AAAA,QACN,0BAA0B;AAAA,QAC1B,OAAO;AAAA,MACT;AAAA,MACA,UAAU;AAAA,IAAA,CACX;AAAA,EAAA;AAGH,QAAM,WAAW;AAAA,IACf,GAAG;AAAA,IACH,QAAQ,OAAO;AAAA,MACb,OAAO,QAAQ,cAAc,MAAM,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AAC7C,cAAA,EAAE,UAAU,OAAA,IAAW;AACtB,eAAA;AAAA,UACL;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,UAAA;AAAA,QAEJ;AAAA,MACD,CAAA;AAAA,IAAA;AAAA,EAEL;AAGO,SAAA;AACT;"}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { isNotFound } from "@tanstack/router-core";
|
|
2
|
-
import invariant from "tiny-invariant";
|
|
3
|
-
import { startSerializer } from "@tanstack/start-client-core";
|
|
4
|
-
import _serverFnManifest from "tanstack:server-fn-manifest";
|
|
5
|
-
import { getResponseStatus, getEvent } from "./h3.js";
|
|
6
|
-
const serverFnManifest = _serverFnManifest;
|
|
7
|
-
function sanitizeBase(base) {
|
|
8
|
-
if (!base) {
|
|
9
|
-
throw new Error(
|
|
10
|
-
"🚨 process.env.TSS_SERVER_FN_BASE is required in start/server-handler/index"
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
return base.replace(/^\/|\/$/g, "");
|
|
14
|
-
}
|
|
15
|
-
const handleServerAction = async ({ request }) => {
|
|
16
|
-
const controller = new AbortController();
|
|
17
|
-
const signal = controller.signal;
|
|
18
|
-
const abort = () => controller.abort();
|
|
19
|
-
request.signal.addEventListener("abort", abort);
|
|
20
|
-
const method = request.method;
|
|
21
|
-
const url = new URL(request.url, "http://localhost:3000");
|
|
22
|
-
const regex = new RegExp(
|
|
23
|
-
`${sanitizeBase(process.env.TSS_SERVER_FN_BASE)}/([^/?#]+)`
|
|
24
|
-
);
|
|
25
|
-
const match = url.pathname.match(regex);
|
|
26
|
-
const serverFnId = match ? match[1] : null;
|
|
27
|
-
const search = Object.fromEntries(url.searchParams.entries());
|
|
28
|
-
const isCreateServerFn = "createServerFn" in search;
|
|
29
|
-
const isRaw = "raw" in search;
|
|
30
|
-
if (typeof serverFnId !== "string") {
|
|
31
|
-
throw new Error("Invalid server action param for serverFnId: " + serverFnId);
|
|
32
|
-
}
|
|
33
|
-
const serverFnInfo = serverFnManifest[serverFnId];
|
|
34
|
-
if (!serverFnInfo) {
|
|
35
|
-
console.info("serverFnManifest", serverFnManifest);
|
|
36
|
-
throw new Error("Server function info not found for " + serverFnId);
|
|
37
|
-
}
|
|
38
|
-
let fnModule;
|
|
39
|
-
if (process.env.NODE_ENV === "development") {
|
|
40
|
-
const serverEnv = globalThis.viteDevServer.environments["server"];
|
|
41
|
-
if (!serverEnv) {
|
|
42
|
-
throw new Error(`'server' vite dev environment not found`);
|
|
43
|
-
}
|
|
44
|
-
fnModule = await serverEnv.runner.import(serverFnInfo.extractedFilename);
|
|
45
|
-
} else {
|
|
46
|
-
fnModule = await serverFnInfo.importer();
|
|
47
|
-
}
|
|
48
|
-
if (!fnModule) {
|
|
49
|
-
console.info("serverFnInfo", serverFnInfo);
|
|
50
|
-
throw new Error("Server function module not resolved for " + serverFnId);
|
|
51
|
-
}
|
|
52
|
-
const action = fnModule[serverFnInfo.functionName];
|
|
53
|
-
if (!action) {
|
|
54
|
-
console.info("serverFnInfo", serverFnInfo);
|
|
55
|
-
console.info("fnModule", fnModule);
|
|
56
|
-
throw new Error(
|
|
57
|
-
`Server function module export not resolved for serverFn ID: ${serverFnId}`
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
const formDataContentTypes = [
|
|
61
|
-
"multipart/form-data",
|
|
62
|
-
"application/x-www-form-urlencoded"
|
|
63
|
-
];
|
|
64
|
-
const response = await (async () => {
|
|
65
|
-
try {
|
|
66
|
-
let result = await (async () => {
|
|
67
|
-
if (request.headers.get("Content-Type") && formDataContentTypes.some(
|
|
68
|
-
(type) => {
|
|
69
|
-
var _a;
|
|
70
|
-
return (_a = request.headers.get("Content-Type")) == null ? void 0 : _a.includes(type);
|
|
71
|
-
}
|
|
72
|
-
)) {
|
|
73
|
-
invariant(
|
|
74
|
-
method.toLowerCase() !== "get",
|
|
75
|
-
"GET requests with FormData payloads are not supported"
|
|
76
|
-
);
|
|
77
|
-
return await action(await request.formData(), signal);
|
|
78
|
-
}
|
|
79
|
-
if (method.toLowerCase() === "get") {
|
|
80
|
-
let payload2 = search;
|
|
81
|
-
if (isCreateServerFn) {
|
|
82
|
-
payload2 = search.payload;
|
|
83
|
-
}
|
|
84
|
-
payload2 = payload2 ? startSerializer.parse(payload2) : payload2;
|
|
85
|
-
return await action(payload2, signal);
|
|
86
|
-
}
|
|
87
|
-
const jsonPayloadAsString = await request.text();
|
|
88
|
-
const payload = startSerializer.parse(jsonPayloadAsString);
|
|
89
|
-
if (isCreateServerFn) {
|
|
90
|
-
return await action(payload, signal);
|
|
91
|
-
}
|
|
92
|
-
return await action(...payload, signal);
|
|
93
|
-
})();
|
|
94
|
-
if (result.result instanceof Response) {
|
|
95
|
-
return result.result;
|
|
96
|
-
}
|
|
97
|
-
if (!isCreateServerFn) {
|
|
98
|
-
result = result.result;
|
|
99
|
-
if (result instanceof Response) {
|
|
100
|
-
return result;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (isNotFound(result)) {
|
|
104
|
-
return isNotFoundResponse(result);
|
|
105
|
-
}
|
|
106
|
-
return new Response(
|
|
107
|
-
result !== void 0 ? startSerializer.stringify(result) : void 0,
|
|
108
|
-
{
|
|
109
|
-
status: getResponseStatus(getEvent()),
|
|
110
|
-
headers: {
|
|
111
|
-
"Content-Type": "application/json"
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
} catch (error) {
|
|
116
|
-
if (error instanceof Response) {
|
|
117
|
-
return error;
|
|
118
|
-
}
|
|
119
|
-
if (isNotFound(error)) {
|
|
120
|
-
return isNotFoundResponse(error);
|
|
121
|
-
}
|
|
122
|
-
console.info();
|
|
123
|
-
console.info("Server Fn Error!");
|
|
124
|
-
console.info();
|
|
125
|
-
console.error(error);
|
|
126
|
-
console.info();
|
|
127
|
-
return new Response(startSerializer.stringify(error), {
|
|
128
|
-
status: 500,
|
|
129
|
-
headers: {
|
|
130
|
-
"Content-Type": "application/json"
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
})();
|
|
135
|
-
request.signal.removeEventListener("abort", abort);
|
|
136
|
-
if (isRaw) {
|
|
137
|
-
return response;
|
|
138
|
-
}
|
|
139
|
-
return response;
|
|
140
|
-
};
|
|
141
|
-
function isNotFoundResponse(error) {
|
|
142
|
-
const { headers, ...rest } = error;
|
|
143
|
-
return new Response(JSON.stringify(rest), {
|
|
144
|
-
status: 200,
|
|
145
|
-
headers: {
|
|
146
|
-
"Content-Type": "application/json",
|
|
147
|
-
...headers || {}
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
export {
|
|
152
|
-
handleServerAction
|
|
153
|
-
};
|
|
154
|
-
//# sourceMappingURL=server-functions-handler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server-functions-handler.js","sources":["../../src/server-functions-handler.ts"],"sourcesContent":["import { isNotFound } from '@tanstack/router-core'\nimport invariant from 'tiny-invariant'\nimport { startSerializer } from '@tanstack/start-client-core'\n// @ts-expect-error\nimport _serverFnManifest from 'tanstack:server-fn-manifest'\nimport { getEvent, getResponseStatus } from './h3'\n\n// NOTE: This is a dummy export to silence warnings about\n// only having a default export.\nexport const dummy = 2\n\nconst serverFnManifest = _serverFnManifest as Record<\n string,\n {\n functionName: string\n extractedFilename: string\n importer: () => Promise<any>\n }\n>\n\nfunction sanitizeBase(base: string | undefined) {\n if (!base) {\n throw new Error(\n '🚨 process.env.TSS_SERVER_FN_BASE is required in start/server-handler/index',\n )\n }\n\n return base.replace(/^\\/|\\/$/g, '')\n}\n\nexport const handleServerAction = async ({ request }: { request: Request }) => {\n const controller = new AbortController()\n const signal = controller.signal\n const abort = () => controller.abort()\n request.signal.addEventListener('abort', abort)\n\n const method = request.method\n const url = new URL(request.url, 'http://localhost:3000')\n // extract the serverFnId from the url as host/_server/:serverFnId\n // Define a regex to match the path and extract the :thing part\n const regex = new RegExp(\n `${sanitizeBase(process.env.TSS_SERVER_FN_BASE)}/([^/?#]+)`,\n )\n\n // Execute the regex\n const match = url.pathname.match(regex)\n const serverFnId = match ? match[1] : null\n const search = Object.fromEntries(url.searchParams.entries()) as {\n payload?: any\n createServerFn?: boolean\n }\n\n const isCreateServerFn = 'createServerFn' in search\n const isRaw = 'raw' in search\n\n if (typeof serverFnId !== 'string') {\n throw new Error('Invalid server action param for serverFnId: ' + serverFnId)\n }\n\n const serverFnInfo = serverFnManifest[serverFnId]\n\n if (!serverFnInfo) {\n console.info('serverFnManifest', serverFnManifest)\n throw new Error('Server function info not found for ' + serverFnId)\n }\n\n let fnModule: undefined | { [key: string]: any }\n\n if (process.env.NODE_ENV === 'development') {\n const serverEnv = (globalThis as any).viteDevServer.environments['server']\n if (!serverEnv) {\n throw new Error(`'server' vite dev environment not found`)\n }\n fnModule = await serverEnv.runner.import(serverFnInfo.extractedFilename)\n } else {\n fnModule = await serverFnInfo.importer()\n }\n\n if (!fnModule) {\n console.info('serverFnInfo', serverFnInfo)\n throw new Error('Server function module not resolved for ' + serverFnId)\n }\n\n const action = fnModule[serverFnInfo.functionName]\n\n if (!action) {\n console.info('serverFnInfo', serverFnInfo)\n console.info('fnModule', fnModule)\n throw new Error(\n `Server function module export not resolved for serverFn ID: ${serverFnId}`,\n )\n }\n\n // Known FormData 'Content-Type' header values\n const formDataContentTypes = [\n 'multipart/form-data',\n 'application/x-www-form-urlencoded',\n ]\n\n const response = await (async () => {\n try {\n let result = await (async () => {\n // FormData\n if (\n request.headers.get('Content-Type') &&\n formDataContentTypes.some((type) =>\n request.headers.get('Content-Type')?.includes(type),\n )\n ) {\n // We don't support GET requests with FormData payloads... that seems impossible\n invariant(\n method.toLowerCase() !== 'get',\n 'GET requests with FormData payloads are not supported',\n )\n\n return await action(await request.formData(), signal)\n }\n\n // Get requests use the query string\n if (method.toLowerCase() === 'get') {\n // By default the payload is the search params\n let payload: any = search\n\n // If this GET request was created by createServerFn,\n // then the payload will be on the payload param\n if (isCreateServerFn) {\n payload = search.payload\n }\n\n // If there's a payload, we should try to parse it\n payload = payload ? startSerializer.parse(payload) : payload\n\n // Send it through!\n return await action(payload, signal)\n }\n\n // This must be a POST request, likely JSON???\n const jsonPayloadAsString = await request.text()\n\n // We should probably try to deserialize the payload\n // as JSON, but we'll just pass it through for now.\n const payload = startSerializer.parse(jsonPayloadAsString)\n\n // If this POST request was created by createServerFn,\n // it's payload will be the only argument\n if (isCreateServerFn) {\n return await action(payload, signal)\n }\n\n // Otherwise, we'll spread the payload. Need to\n // support `use server` functions that take multiple\n // arguments.\n return await action(...(payload as any), signal)\n })()\n\n // Any time we get a Response back, we should just\n // return it immediately.\n if (result.result instanceof Response) {\n return result.result\n }\n\n // If this is a non createServerFn request, we need to\n // pull out the result from the result object\n if (!isCreateServerFn) {\n result = result.result\n\n // The result might again be a response,\n // and if it is, return it.\n if (result instanceof Response) {\n return result\n }\n }\n\n // if (!search.createServerFn) {\n // result = result.result\n // }\n\n // else if (\n // isPlainObject(result) &&\n // 'result' in result &&\n // result.result instanceof Response\n // ) {\n // return result.result\n // }\n\n // TODO: RSCs Where are we getting this package?\n // if (isValidElement(result)) {\n // const { renderToPipeableStream } = await import(\n // // @ts-expect-error\n // 'react-server-dom/server'\n // )\n\n // const pipeableStream = renderToPipeableStream(result)\n\n // setHeaders(event, {\n // 'Content-Type': 'text/x-component',\n // } as any)\n\n // sendStream(event, response)\n // event._handled = true\n\n // return new Response(null, { status: 200 })\n // }\n\n if (isNotFound(result)) {\n return isNotFoundResponse(result)\n }\n\n return new Response(\n result !== undefined ? startSerializer.stringify(result) : undefined,\n {\n status: getResponseStatus(getEvent()),\n headers: {\n 'Content-Type': 'application/json',\n },\n },\n )\n } catch (error: any) {\n if (error instanceof Response) {\n return error\n }\n // else if (\n // isPlainObject(error) &&\n // 'result' in error &&\n // error.result instanceof Response\n // ) {\n // return error.result\n // }\n\n // Currently this server-side context has no idea how to\n // build final URLs, so we need to defer that to the client.\n // The client will check for __redirect and __notFound keys,\n // and if they exist, it will handle them appropriately.\n\n if (isNotFound(error)) {\n return isNotFoundResponse(error)\n }\n\n console.info()\n console.info('Server Fn Error!')\n console.info()\n console.error(error)\n console.info()\n\n return new Response(startSerializer.stringify(error), {\n status: 500,\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n }\n })()\n\n request.signal.removeEventListener('abort', abort)\n\n if (isRaw) {\n return response\n }\n\n return response\n}\n\nfunction isNotFoundResponse(error: any) {\n const { headers, ...rest } = error\n\n return new Response(JSON.stringify(rest), {\n status: 200,\n headers: {\n 'Content-Type': 'application/json',\n ...(headers || {}),\n },\n })\n}\n"],"names":["payload"],"mappings":"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"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { Assign, Constrain, Expand, ResolveParams, RouteConstraints, TrimPathRight } from '@tanstack/router-core';
|
|
2
|
-
import { AnyRequestMiddleware, AssignAllServerContext } from '@tanstack/start-client-core';
|
|
3
|
-
type TODO = any;
|
|
4
|
-
export declare function createServerFileRoute<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren>(__?: never): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
5
|
-
export interface ServerRouteOptions<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares> {
|
|
6
|
-
id: TId;
|
|
7
|
-
path: TPath;
|
|
8
|
-
pathname: TFullPath;
|
|
9
|
-
originalIndex: number;
|
|
10
|
-
getParentRoute?: () => TParentRoute;
|
|
11
|
-
middleware: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>;
|
|
12
|
-
methods: Record<string, ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, any, any>>;
|
|
13
|
-
caseSensitive?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export type ServerRouteManifest = {
|
|
16
|
-
middleware: boolean;
|
|
17
|
-
methods: Record<string, {
|
|
18
|
-
middleware: boolean;
|
|
19
|
-
}>;
|
|
20
|
-
};
|
|
21
|
-
export declare function createServerRoute<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren>(__?: never, __opts?: Partial<ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>>): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
22
|
-
export type ServerRouteAddFileChildrenFn<in out TParentRoute extends AnyServerRouteWithTypes, in out TId extends RouteConstraints['TId'], in out TPath extends RouteConstraints['TPath'], in out TFullPath extends RouteConstraints['TFullPath'], in out TMiddlewares, in out TMethods, in out TChildren> = (children: TChildren) => ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
23
|
-
export type CreateServerFileRoute<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren> = (options?: undefined) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
24
|
-
export type AnyServerRouteWithTypes = ServerRouteWithTypes<any, any, any, any, any, any, any>;
|
|
25
|
-
export interface ServerRouteWithTypes<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TMethods, TChildren> {
|
|
26
|
-
_types: ServerRouteTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods>;
|
|
27
|
-
path: TPath;
|
|
28
|
-
id: TId;
|
|
29
|
-
fullPath: TFullPath;
|
|
30
|
-
to: TrimPathRight<TFullPath>;
|
|
31
|
-
parentRoute: TParentRoute;
|
|
32
|
-
children?: TChildren;
|
|
33
|
-
options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>;
|
|
34
|
-
update: (opts: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
35
|
-
init: (opts: {
|
|
36
|
-
originalIndex: number;
|
|
37
|
-
}) => void;
|
|
38
|
-
_addFileChildren: ServerRouteAddFileChildrenFn<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
39
|
-
_addFileTypes: () => ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
40
|
-
}
|
|
41
|
-
export interface ServerRouteTypes<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TMethods> {
|
|
42
|
-
id: TId;
|
|
43
|
-
path: TPath;
|
|
44
|
-
fullPath: TFullPath;
|
|
45
|
-
middlewares: TMiddlewares;
|
|
46
|
-
methods: TMethods;
|
|
47
|
-
parentRoute: TParentRoute;
|
|
48
|
-
allContext: ResolveAllServerContext<TParentRoute, TMiddlewares>;
|
|
49
|
-
}
|
|
50
|
-
export type ResolveAllServerContext<TParentRoute extends AnyServerRouteWithTypes, TMiddlewares> = unknown extends TParentRoute ? AssignAllServerContext<TMiddlewares> : Assign<TParentRoute['_types']['allContext'], AssignAllServerContext<TMiddlewares>>;
|
|
51
|
-
export type AnyServerRoute = AnyServerRouteWithTypes;
|
|
52
|
-
export interface ServerRoute<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren> extends ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, undefined, undefined, TChildren>, ServerRouteMiddleware<TParentRoute, TId, TPath, TFullPath, TChildren>, ServerRouteMethods<TParentRoute, TId, TPath, TFullPath, undefined, TChildren> {
|
|
53
|
-
}
|
|
54
|
-
export interface ServerRouteMiddleware<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren> {
|
|
55
|
-
middleware: <const TNewMiddleware>(middleware: Constrain<TNewMiddleware, ReadonlyArray<AnyRequestMiddleware>>) => ServerRouteAfterMiddleware<TParentRoute, TId, TPath, TFullPath, TNewMiddleware, TChildren>;
|
|
56
|
-
}
|
|
57
|
-
export interface ServerRouteAfterMiddleware<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TChildren> extends ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, undefined, TChildren>, ServerRouteMethods<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TChildren> {
|
|
58
|
-
}
|
|
59
|
-
export interface ServerRouteMethods<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TChildren> {
|
|
60
|
-
methods: <const TMethods>(methodsOrGetMethods: Constrain<TMethods, ServerRouteMethodsOptions<TParentRoute, TFullPath, TMiddlewares>>) => ServerRouteAfterMethods<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
61
|
-
}
|
|
62
|
-
export type ServerRouteMethodsOptions<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> = ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares> | ((api: ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares>) => ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>);
|
|
63
|
-
export interface ServerRouteMethodsRecord<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> {
|
|
64
|
-
GET?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
65
|
-
POST?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
66
|
-
PUT?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
67
|
-
PATCH?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
68
|
-
DELETE?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
69
|
-
OPTIONS?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
70
|
-
HEAD?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
71
|
-
}
|
|
72
|
-
export type ServerRouteMethodRecordValue<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> = ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, undefined, any> | AnyRouteMethodsBuilder;
|
|
73
|
-
export type ServerRouteVerb = (typeof ServerRouteVerbs)[number];
|
|
74
|
-
export declare const ServerRouteVerbs: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
75
|
-
export type ServerRouteMethodHandlerFn<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> = (ctx: ServerRouteMethodHandlerCtx<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares>) => TResponse | Promise<TResponse>;
|
|
76
|
-
export interface ServerRouteMethodHandlerCtx<in out TParentRoute extends AnyServerRouteWithTypes, in out TFullPath extends string, in out TMiddlewares, in out TMethodMiddlewares> {
|
|
77
|
-
context: Expand<AssignAllMethodContext<TParentRoute, TMiddlewares, TMethodMiddlewares>>;
|
|
78
|
-
request: Request;
|
|
79
|
-
params: ResolveParams<TFullPath>;
|
|
80
|
-
pathname: TFullPath;
|
|
81
|
-
}
|
|
82
|
-
export type MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares> = TMiddlewares extends ReadonlyArray<any> ? TMethodMiddlewares extends ReadonlyArray<any> ? readonly [...TMiddlewares, ...TMethodMiddlewares] : TMiddlewares : TMethodMiddlewares;
|
|
83
|
-
export type AssignAllMethodContext<TParentRoute extends AnyServerRouteWithTypes, TMiddlewares, TMethodMiddlewares> = ResolveAllServerContext<TParentRoute, MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares>>;
|
|
84
|
-
export type AnyRouteMethodsBuilder = ServerRouteMethodBuilderWithTypes<any, any, any, any>;
|
|
85
|
-
export interface ServerRouteMethodBuilder<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> extends ServerRouteMethodBuilderWithTypes<TFullPath, TMiddlewares, undefined, undefined>, ServerRouteMethodBuilderMiddleware<TParentRoute, TFullPath, TMiddlewares>, ServerRouteMethodBuilderHandler<TParentRoute, TFullPath, TMiddlewares, undefined> {
|
|
86
|
-
}
|
|
87
|
-
export interface ServerRouteMethodBuilderWithTypes<TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> {
|
|
88
|
-
_options: TODO;
|
|
89
|
-
_types: ServerRouteMethodBuilderTypes<TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
90
|
-
}
|
|
91
|
-
export interface ServerRouteMethodBuilderTypes<in out TFullPath extends string, in out TMiddlewares, in out TMethodMiddlewares, in out TResponse> {
|
|
92
|
-
middlewares: TMiddlewares;
|
|
93
|
-
methodMiddleware: TMethodMiddlewares;
|
|
94
|
-
fullPath: TFullPath;
|
|
95
|
-
response: TResponse;
|
|
96
|
-
}
|
|
97
|
-
export interface ServerRouteMethodBuilderMiddleware<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> {
|
|
98
|
-
middleware: <const TNewMethodMiddlewares>(middleware: Constrain<TNewMethodMiddlewares, ReadonlyArray<AnyRequestMiddleware>>) => ServerRouteMethodBuilderAfterMiddleware<TParentRoute, TFullPath, TMiddlewares, TNewMethodMiddlewares>;
|
|
99
|
-
}
|
|
100
|
-
export interface ServerRouteMethodBuilderAfterMiddleware<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> extends ServerRouteMethodBuilderWithTypes<TFullPath, TMiddlewares, TMethodMiddlewares, undefined>, ServerRouteMethodBuilderHandler<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares> {
|
|
101
|
-
}
|
|
102
|
-
export interface ServerRouteMethodBuilderHandler<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> {
|
|
103
|
-
handler: <TResponse>(handler: ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>) => ServerRouteMethodBuilderAfterHandler<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
104
|
-
}
|
|
105
|
-
export interface ServerRouteMethodBuilderAfterHandler<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> extends ServerRouteMethodBuilderWithTypes<TFullPath, TMiddlewares, TMethodMiddlewares, TResponse> {
|
|
106
|
-
opts: ServerRouteMethod<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares>;
|
|
107
|
-
}
|
|
108
|
-
export interface ServerRouteMethod<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> {
|
|
109
|
-
middleware?: Constrain<TMiddlewares, Array<AnyRequestMiddleware>>;
|
|
110
|
-
handler?: ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, undefined>;
|
|
111
|
-
}
|
|
112
|
-
export interface ServerRouteAfterMethods<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TMethods, TChildren> extends ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren> {
|
|
113
|
-
options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>;
|
|
114
|
-
}
|
|
115
|
-
export {};
|
package/dist/esm/serverRoute.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { rootRouteId, trimPathLeft, joinPaths } from "@tanstack/router-core";
|
|
2
|
-
function createServerFileRoute(__) {
|
|
3
|
-
return createServerRoute();
|
|
4
|
-
}
|
|
5
|
-
function createServerRoute(__, __opts) {
|
|
6
|
-
const options = __opts || {};
|
|
7
|
-
const route = {
|
|
8
|
-
path: "",
|
|
9
|
-
id: "",
|
|
10
|
-
fullPath: "",
|
|
11
|
-
to: "",
|
|
12
|
-
options,
|
|
13
|
-
parentRoute: void 0,
|
|
14
|
-
_types: {},
|
|
15
|
-
// children: undefined as TChildren,
|
|
16
|
-
middleware: (middlewares) => createServerRoute(void 0, {
|
|
17
|
-
...options,
|
|
18
|
-
middleware: middlewares
|
|
19
|
-
}),
|
|
20
|
-
methods: (methodsOrGetMethods) => {
|
|
21
|
-
const methods = (() => {
|
|
22
|
-
if (typeof methodsOrGetMethods === "function") {
|
|
23
|
-
return methodsOrGetMethods(createMethodBuilder());
|
|
24
|
-
}
|
|
25
|
-
return methodsOrGetMethods;
|
|
26
|
-
})();
|
|
27
|
-
return createServerRoute(void 0, {
|
|
28
|
-
...__opts,
|
|
29
|
-
methods
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
update: (opts) => createServerRoute(void 0, {
|
|
33
|
-
...options,
|
|
34
|
-
...opts
|
|
35
|
-
}),
|
|
36
|
-
init: (opts) => {
|
|
37
|
-
var _a;
|
|
38
|
-
options.originalIndex = opts.originalIndex;
|
|
39
|
-
const isRoot = !options.path && !options.id;
|
|
40
|
-
route.parentRoute = (_a = options.getParentRoute) == null ? void 0 : _a.call(options);
|
|
41
|
-
if (isRoot) {
|
|
42
|
-
route.path = rootRouteId;
|
|
43
|
-
} else if (!route.parentRoute) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
`Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a ServerRoute instance.`
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
let path = isRoot ? rootRouteId : options.path;
|
|
49
|
-
if (path && path !== "/") {
|
|
50
|
-
path = trimPathLeft(path);
|
|
51
|
-
}
|
|
52
|
-
const customId = options.id || path;
|
|
53
|
-
let id = isRoot ? rootRouteId : joinPaths([
|
|
54
|
-
route.parentRoute.id === rootRouteId ? "" : route.parentRoute.id,
|
|
55
|
-
customId
|
|
56
|
-
]);
|
|
57
|
-
if (path === rootRouteId) {
|
|
58
|
-
path = "/";
|
|
59
|
-
}
|
|
60
|
-
if (id !== rootRouteId) {
|
|
61
|
-
id = joinPaths(["/", id]);
|
|
62
|
-
}
|
|
63
|
-
const fullPath = id === rootRouteId ? "/" : joinPaths([route.parentRoute.fullPath, path]);
|
|
64
|
-
route.path = path;
|
|
65
|
-
route.id = id;
|
|
66
|
-
route.fullPath = fullPath;
|
|
67
|
-
route.to = fullPath;
|
|
68
|
-
},
|
|
69
|
-
_addFileChildren: (children) => {
|
|
70
|
-
if (Array.isArray(children)) {
|
|
71
|
-
route.children = children;
|
|
72
|
-
}
|
|
73
|
-
if (typeof children === "object" && children !== null) {
|
|
74
|
-
route.children = Object.values(children);
|
|
75
|
-
}
|
|
76
|
-
return route;
|
|
77
|
-
},
|
|
78
|
-
_addFileTypes: () => route
|
|
79
|
-
};
|
|
80
|
-
return route;
|
|
81
|
-
}
|
|
82
|
-
const createMethodBuilder = (__opts) => {
|
|
83
|
-
return {
|
|
84
|
-
_options: __opts || {},
|
|
85
|
-
_types: {},
|
|
86
|
-
middleware: (middlewares) => createMethodBuilder({
|
|
87
|
-
...__opts,
|
|
88
|
-
middlewares
|
|
89
|
-
}),
|
|
90
|
-
handler: (handler) => createMethodBuilder({
|
|
91
|
-
...__opts,
|
|
92
|
-
handler
|
|
93
|
-
})
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
export {
|
|
97
|
-
createServerFileRoute,
|
|
98
|
-
createServerRoute
|
|
99
|
-
};
|
|
100
|
-
//# sourceMappingURL=serverRoute.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serverRoute.js","sources":["../../src/serverRoute.ts"],"sourcesContent":["import { joinPaths, rootRouteId, trimPathLeft } from '@tanstack/router-core'\nimport type {\n Assign,\n Constrain,\n Expand,\n ResolveParams,\n RouteConstraints,\n TrimPathRight,\n} from '@tanstack/router-core'\nimport type {\n AnyRequestMiddleware,\n AssignAllServerContext,\n} from '@tanstack/start-client-core'\n\ntype TODO = any\n\nexport function createServerFileRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n>(__?: never): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {\n return createServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>(\n undefined,\n )\n}\n\nexport interface ServerRouteOptions<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n> {\n id: TId\n path: TPath\n pathname: TFullPath\n originalIndex: number\n getParentRoute?: () => TParentRoute\n middleware: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>\n methods: Record<\n string,\n ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, any, any>\n >\n caseSensitive?: boolean\n}\n\nexport type ServerRouteManifest = {\n middleware: boolean\n methods: Record<string, { middleware: boolean }>\n}\n\nexport function createServerRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n>(\n __?: never,\n __opts?: Partial<\n ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>\n >,\n): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {\n const options = __opts || {}\n\n const route: ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> = {\n path: '' as TPath,\n id: '' as TId,\n fullPath: '' as TFullPath,\n to: '' as TrimPathRight<TFullPath>,\n options: options as TODO,\n parentRoute: undefined as unknown as TParentRoute,\n _types: {} as TODO,\n // children: undefined as TChildren,\n middleware: (middlewares: TODO) =>\n createServerRoute(undefined, {\n ...options,\n middleware: middlewares,\n }) as TODO,\n methods: (methodsOrGetMethods: TODO) => {\n const methods = (() => {\n if (typeof methodsOrGetMethods === 'function') {\n return methodsOrGetMethods(createMethodBuilder())\n }\n\n return methodsOrGetMethods\n })()\n\n return createServerRoute(undefined, {\n ...__opts,\n methods,\n }) as TODO\n },\n update: (opts) =>\n createServerRoute(undefined, {\n ...options,\n ...opts,\n }) as TODO,\n init: (opts: { originalIndex: number }): void => {\n options.originalIndex = opts.originalIndex\n\n const isRoot = !options.path && !options.id\n\n route.parentRoute = options.getParentRoute?.() as TParentRoute\n\n if (isRoot) {\n route.path = rootRouteId as TPath\n } else if (!(route.parentRoute as any)) {\n throw new Error(\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a ServerRoute instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPathLeft(path)\n }\n\n const customId = options.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n route.parentRoute.id === rootRouteId ? '' : route.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([route.parentRoute.fullPath, path])\n\n route.path = path as TPath\n route.id = id as TId\n route.fullPath = fullPath as TFullPath\n route.to = fullPath as TrimPathRight<TFullPath>\n },\n\n _addFileChildren: (children) => {\n if (Array.isArray(children)) {\n route.children = children as TChildren as TODO\n }\n\n if (typeof children === 'object' && children !== null) {\n route.children = Object.values(children) as TChildren as TODO\n }\n\n return route as any\n },\n\n _addFileTypes: <TFileTypes>() => route,\n }\n\n return route\n}\n\nexport type ServerRouteAddFileChildrenFn<\n in out TParentRoute extends AnyServerRouteWithTypes,\n in out TId extends RouteConstraints['TId'],\n in out TPath extends RouteConstraints['TPath'],\n in out TFullPath extends RouteConstraints['TFullPath'],\n in out TMiddlewares,\n in out TMethods,\n in out TChildren,\n> = (\n children: TChildren,\n) => ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n>\n\nconst createMethodBuilder = <\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n>(\n __opts?: TODO,\n): ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares> => {\n return {\n _options: __opts || {},\n _types: {} as TODO,\n middleware: (middlewares) =>\n createMethodBuilder({\n ...__opts,\n middlewares,\n }) as TODO,\n handler: (handler) =>\n createMethodBuilder({\n ...__opts,\n handler,\n }) as TODO,\n }\n}\n\nexport type CreateServerFileRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> = (\n options?: undefined,\n) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>\n\nexport type AnyServerRouteWithTypes = ServerRouteWithTypes<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n\nexport interface ServerRouteWithTypes<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n TChildren,\n> {\n _types: ServerRouteTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods\n >\n path: TPath\n id: TId\n fullPath: TFullPath\n to: TrimPathRight<TFullPath>\n parentRoute: TParentRoute\n children?: TChildren\n options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>\n update: (\n opts: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>,\n ) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>\n init: (opts: { originalIndex: number }) => void\n _addFileChildren: ServerRouteAddFileChildrenFn<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n _addFileTypes: () => ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n}\n\nexport interface ServerRouteTypes<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n> {\n id: TId\n path: TPath\n fullPath: TFullPath\n middlewares: TMiddlewares\n methods: TMethods\n parentRoute: TParentRoute\n allContext: ResolveAllServerContext<TParentRoute, TMiddlewares>\n}\n\nexport type ResolveAllServerContext<\n TParentRoute extends AnyServerRouteWithTypes,\n TMiddlewares,\n> = unknown extends TParentRoute\n ? AssignAllServerContext<TMiddlewares>\n : Assign<\n TParentRoute['_types']['allContext'],\n AssignAllServerContext<TMiddlewares>\n >\n\nexport type AnyServerRoute = AnyServerRouteWithTypes\n\nexport interface ServerRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n undefined,\n undefined,\n TChildren\n >,\n ServerRouteMiddleware<TParentRoute, TId, TPath, TFullPath, TChildren>,\n ServerRouteMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n undefined,\n TChildren\n > {}\n\nexport interface ServerRouteMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> {\n middleware: <const TNewMiddleware>(\n middleware: Constrain<TNewMiddleware, ReadonlyArray<AnyRequestMiddleware>>,\n ) => ServerRouteAfterMiddleware<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TNewMiddleware,\n TChildren\n >\n}\n\nexport interface ServerRouteAfterMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n undefined,\n TChildren\n >,\n ServerRouteMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TChildren\n > {}\n\nexport interface ServerRouteMethods<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TChildren,\n> {\n methods: <const TMethods>(\n methodsOrGetMethods: Constrain<\n TMethods,\n ServerRouteMethodsOptions<TParentRoute, TFullPath, TMiddlewares>\n >,\n ) => ServerRouteAfterMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n}\n\nexport type ServerRouteMethodsOptions<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> =\n | ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>\n | ((\n api: ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares>,\n ) => ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>)\n\nexport interface ServerRouteMethodsRecord<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> {\n GET?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n POST?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n PUT?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n PATCH?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n DELETE?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n OPTIONS?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n HEAD?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n}\n\nexport type ServerRouteMethodRecordValue<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> =\n | ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n undefined,\n any\n >\n | AnyRouteMethodsBuilder\n\nexport type ServerRouteVerb = (typeof ServerRouteVerbs)[number]\n\nexport const ServerRouteVerbs = [\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n] as const\n\nexport type ServerRouteMethodHandlerFn<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> = (\n ctx: ServerRouteMethodHandlerCtx<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n >,\n) => TResponse | Promise<TResponse>\n\nexport interface ServerRouteMethodHandlerCtx<\n in out TParentRoute extends AnyServerRouteWithTypes,\n in out TFullPath extends string,\n in out TMiddlewares,\n in out TMethodMiddlewares,\n> {\n context: Expand<\n AssignAllMethodContext<TParentRoute, TMiddlewares, TMethodMiddlewares>\n >\n request: Request\n params: ResolveParams<TFullPath>\n pathname: TFullPath\n}\n\nexport type MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares> =\n TMiddlewares extends ReadonlyArray<any>\n ? TMethodMiddlewares extends ReadonlyArray<any>\n ? readonly [...TMiddlewares, ...TMethodMiddlewares]\n : TMiddlewares\n : TMethodMiddlewares\n\nexport type AssignAllMethodContext<\n TParentRoute extends AnyServerRouteWithTypes,\n TMiddlewares,\n TMethodMiddlewares,\n> = ResolveAllServerContext<\n TParentRoute,\n MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares>\n>\n\nexport type AnyRouteMethodsBuilder = ServerRouteMethodBuilderWithTypes<\n any,\n any,\n any,\n any\n>\n\nexport interface ServerRouteMethodBuilder<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> extends ServerRouteMethodBuilderWithTypes<\n TFullPath,\n TMiddlewares,\n undefined,\n undefined\n >,\n ServerRouteMethodBuilderMiddleware<TParentRoute, TFullPath, TMiddlewares>,\n ServerRouteMethodBuilderHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n undefined\n > {}\n\nexport interface ServerRouteMethodBuilderWithTypes<\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> {\n _options: TODO\n _types: ServerRouteMethodBuilderTypes<\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\n}\n\nexport interface ServerRouteMethodBuilderTypes<\n in out TFullPath extends string,\n in out TMiddlewares,\n in out TMethodMiddlewares,\n in out TResponse,\n> {\n middlewares: TMiddlewares\n methodMiddleware: TMethodMiddlewares\n fullPath: TFullPath\n response: TResponse\n}\n\nexport interface ServerRouteMethodBuilderMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> {\n middleware: <const TNewMethodMiddlewares>(\n middleware: Constrain<\n TNewMethodMiddlewares,\n ReadonlyArray<AnyRequestMiddleware>\n >,\n ) => ServerRouteMethodBuilderAfterMiddleware<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TNewMethodMiddlewares\n >\n}\n\nexport interface ServerRouteMethodBuilderAfterMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> extends ServerRouteMethodBuilderWithTypes<\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n undefined\n >,\n ServerRouteMethodBuilderHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n > {}\n\nexport interface ServerRouteMethodBuilderHandler<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> {\n handler: <TResponse>(\n handler: ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >,\n ) => ServerRouteMethodBuilderAfterHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\n}\n\nexport interface ServerRouteMethodBuilderAfterHandler<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> extends ServerRouteMethodBuilderWithTypes<\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n > {\n opts: ServerRouteMethod<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n >\n}\n\nexport interface ServerRouteMethod<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> {\n middleware?: Constrain<TMiddlewares, Array<AnyRequestMiddleware>>\n handler?: ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n undefined\n >\n}\n\nexport interface ServerRouteAfterMethods<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n > {\n options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>\n}\n"],"names":[],"mappings":";AAgBO,SAAS,sBAMd,IAAyE;AAClE,SAAA,kBAEP;AACF;AA2BgB,SAAA,kBAOd,IACA,QAG6D;AACvD,QAAA,UAAU,UAAU,CAAC;AAE3B,QAAM,QAAqE;AAAA,IACzE,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,UAAU;AAAA,IACV,IAAI;AAAA,IACJ;AAAA,IACA,aAAa;AAAA,IACb,QAAQ,CAAC;AAAA;AAAA,IAET,YAAY,CAAC,gBACX,kBAAkB,QAAW;AAAA,MAC3B,GAAG;AAAA,MACH,YAAY;AAAA,IAAA,CACb;AAAA,IACH,SAAS,CAAC,wBAA8B;AACtC,YAAM,WAAW,MAAM;AACjB,YAAA,OAAO,wBAAwB,YAAY;AACtC,iBAAA,oBAAoB,qBAAqB;AAAA,QAAA;AAG3C,eAAA;AAAA,MAAA,GACN;AAEH,aAAO,kBAAkB,QAAW;AAAA,QAClC,GAAG;AAAA,QACH;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,QAAQ,CAAC,SACP,kBAAkB,QAAW;AAAA,MAC3B,GAAG;AAAA,MACH,GAAG;AAAA,IAAA,CACJ;AAAA,IACH,MAAM,CAAC,SAA0C;;AAC/C,cAAQ,gBAAgB,KAAK;AAE7B,YAAM,SAAS,CAAC,QAAQ,QAAQ,CAAC,QAAQ;AAEnC,YAAA,eAAc,aAAQ,mBAAR;AAEpB,UAAI,QAAQ;AACV,cAAM,OAAO;AAAA,MAAA,WACJ,CAAE,MAAM,aAAqB;AACtC,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MAAA;AAGE,UAAA,OAA2B,SAAS,cAAc,QAAQ;AAG1D,UAAA,QAAQ,SAAS,KAAK;AACxB,eAAO,aAAa,IAAI;AAAA,MAAA;AAGpB,YAAA,WAAW,QAAQ,MAAM;AAG3B,UAAA,KAAK,SACL,cACA,UAAU;AAAA,QACR,MAAM,YAAY,OAAO,cAAc,KAAK,MAAM,YAAY;AAAA,QAC9D;AAAA,MAAA,CACD;AAEL,UAAI,SAAS,aAAa;AACjB,eAAA;AAAA,MAAA;AAGT,UAAI,OAAO,aAAa;AACtB,aAAK,UAAU,CAAC,KAAK,EAAE,CAAC;AAAA,MAAA;AAGpB,YAAA,WACJ,OAAO,cAAc,MAAM,UAAU,CAAC,MAAM,YAAY,UAAU,IAAI,CAAC;AAEzE,YAAM,OAAO;AACb,YAAM,KAAK;AACX,YAAM,WAAW;AACjB,YAAM,KAAK;AAAA,IACb;AAAA,IAEA,kBAAkB,CAAC,aAAa;AAC1B,UAAA,MAAM,QAAQ,QAAQ,GAAG;AAC3B,cAAM,WAAW;AAAA,MAAA;AAGnB,UAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AAC/C,cAAA,WAAW,OAAO,OAAO,QAAQ;AAAA,MAAA;AAGlC,aAAA;AAAA,IACT;AAAA,IAEA,eAAe,MAAkB;AAAA,EACnC;AAEO,SAAA;AACT;AAsBA,MAAM,sBAAsB,CAK1B,WACoE;AAC7D,SAAA;AAAA,IACL,UAAU,UAAU,CAAC;AAAA,IACrB,QAAQ,CAAC;AAAA,IACT,YAAY,CAAC,gBACX,oBAAoB;AAAA,MAClB,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,IACH,SAAS,CAAC,YACR,oBAAoB;AAAA,MAClB,GAAG;AAAA,MACH;AAAA,IACD,CAAA;AAAA,EACL;AACF;"}
|
package/dist/esm/undici.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { setGlobalOrigin } from 'undici';
|
|
2
|
-
/**
|
|
3
|
-
* DO NOT USE THIS FUNCTION. THIS FUNCTION IS FOR INTERNAL USE ONLY.
|
|
4
|
-
*
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export declare const __setGlobalOrigin: typeof setGlobalOrigin;
|
|
8
|
-
/**
|
|
9
|
-
* DO NOT USE THIS FUNCTION. THIS FUNCTION IS FOR INTERNAL USE ONLY.
|
|
10
|
-
*
|
|
11
|
-
* Constructs an absolute URL from the given request object and options.
|
|
12
|
-
*
|
|
13
|
-
* @internal
|
|
14
|
-
* @param req - The `Request` object containing the headers to extract the host and protocol.
|
|
15
|
-
* @param options - Configuration options for determining the trust level of proxy headers.
|
|
16
|
-
* @param options.trustProxy - If `true`, the function will trust the `x-forwarded-host` and `x-forwarded-proto` headers
|
|
17
|
-
* to determine the host and protocol. Defaults to `false`.
|
|
18
|
-
* @returns The absolute URL constructed from the request headers as a string.
|
|
19
|
-
* @throws Will throw an error if the `host` cannot be determined from the request headers.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* // Example usage:
|
|
24
|
-
* const req = new Request('http://example.com', {
|
|
25
|
-
* headers: {
|
|
26
|
-
* 'host': 'example.com',
|
|
27
|
-
* 'x-forwarded-host': 'proxy.example.com',
|
|
28
|
-
* 'x-forwarded-proto': 'https',
|
|
29
|
-
* },
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* // Without trusting proxy headers
|
|
33
|
-
* const url1 = getAbsoluteUrl(req);
|
|
34
|
-
* console.log(url1); // Output: "http://example.com"
|
|
35
|
-
*
|
|
36
|
-
* // With trusting proxy headers
|
|
37
|
-
* const url2 = getAbsoluteUrl(req, { trustProxy: true });
|
|
38
|
-
* console.log(url2); // Output: "https://proxy.example.com"
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare function __getAbsoluteUrl(req: Request, options?: {
|
|
42
|
-
trustProxy: boolean;
|
|
43
|
-
}): string;
|
package/dist/esm/undici.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { setGlobalOrigin } from "undici";
|
|
2
|
-
const __setGlobalOrigin = setGlobalOrigin;
|
|
3
|
-
function __getAbsoluteUrl(req, options = { trustProxy: false }) {
|
|
4
|
-
const headers = req.headers;
|
|
5
|
-
const host = options.trustProxy ? headers.get("x-forwarded-host") || headers.get("host") : headers.get("host");
|
|
6
|
-
const protocol = options.trustProxy ? headers.get("x-forwarded-proto") || "http" : "http";
|
|
7
|
-
if (!host) throw new Error("Cannot determine host from request headers");
|
|
8
|
-
return `${protocol}://${host}`;
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
__getAbsoluteUrl,
|
|
12
|
-
__setGlobalOrigin
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=undici.js.map
|
package/dist/esm/undici.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"undici.js","sources":["../../src/undici.ts"],"sourcesContent":["import { setGlobalOrigin } from 'undici'\n\n/**\n * DO NOT USE THIS FUNCTION. THIS FUNCTION IS FOR INTERNAL USE ONLY.\n *\n * @internal\n */\nexport const __setGlobalOrigin = setGlobalOrigin\n\n/**\n * DO NOT USE THIS FUNCTION. THIS FUNCTION IS FOR INTERNAL USE ONLY.\n *\n * Constructs an absolute URL from the given request object and options.\n *\n * @internal\n * @param req - The `Request` object containing the headers to extract the host and protocol.\n * @param options - Configuration options for determining the trust level of proxy headers.\n * @param options.trustProxy - If `true`, the function will trust the `x-forwarded-host` and `x-forwarded-proto` headers\n * to determine the host and protocol. Defaults to `false`.\n * @returns The absolute URL constructed from the request headers as a string.\n * @throws Will throw an error if the `host` cannot be determined from the request headers.\n *\n * @example\n * ```ts\n * // Example usage:\n * const req = new Request('http://example.com', {\n * headers: {\n * 'host': 'example.com',\n * 'x-forwarded-host': 'proxy.example.com',\n * 'x-forwarded-proto': 'https',\n * },\n * });\n *\n * // Without trusting proxy headers\n * const url1 = getAbsoluteUrl(req);\n * console.log(url1); // Output: \"http://example.com\"\n *\n * // With trusting proxy headers\n * const url2 = getAbsoluteUrl(req, { trustProxy: true });\n * console.log(url2); // Output: \"https://proxy.example.com\"\n * ```\n */\nexport function __getAbsoluteUrl(\n req: Request,\n options: { trustProxy: boolean } = { trustProxy: false },\n): string {\n const headers = req.headers\n\n const host = options.trustProxy\n ? headers.get('x-forwarded-host') || headers.get('host')\n : headers.get('host')\n\n const protocol = options.trustProxy\n ? headers.get('x-forwarded-proto') || 'http'\n : 'http'\n\n if (!host) throw new Error('Cannot determine host from request headers')\n\n return `${protocol}://${host}`\n}\n"],"names":[],"mappings":";AAOO,MAAM,oBAAoB;AAmC1B,SAAS,iBACd,KACA,UAAmC,EAAE,YAAY,SACzC;AACR,QAAM,UAAU,IAAI;AAEpB,QAAM,OAAO,QAAQ,aACjB,QAAQ,IAAI,kBAAkB,KAAK,QAAQ,IAAI,MAAM,IACrD,QAAQ,IAAI,MAAM;AAEtB,QAAM,WAAW,QAAQ,aACrB,QAAQ,IAAI,mBAAmB,KAAK,SACpC;AAEJ,MAAI,CAAC,KAAY,OAAA,IAAI,MAAM,4CAA4C;AAEhE,SAAA,GAAG,QAAQ,MAAM,IAAI;AAC9B;"}
|