@solidjs/start 1.2.0 → 2.0.0-alpha.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/README.md +88 -8
- package/dist/client/StartClient.d.ts +0 -1
- package/dist/client/StartClient.jsx +2 -4
- package/dist/client/index.d.ts +2 -3
- package/dist/client/index.jsx +2 -4
- package/dist/client/mount.js +10 -2
- package/dist/client/spa/index.d.ts +1 -2
- package/dist/client/spa/index.jsx +1 -2
- package/dist/config/constants.d.ts +16 -0
- package/dist/config/constants.js +16 -0
- package/dist/config/dev-server.d.ts +2 -0
- package/dist/config/dev-server.js +108 -0
- package/dist/config/fs-router.d.ts +37 -0
- package/dist/config/fs-router.js +153 -0
- package/dist/config/fs-routes/fs-watcher.d.ts +3 -0
- package/dist/config/fs-routes/fs-watcher.js +49 -0
- package/dist/config/fs-routes/index.d.ts +7 -0
- package/dist/config/fs-routes/index.js +109 -0
- package/dist/config/fs-routes/router.d.ts +37 -0
- package/dist/config/fs-routes/router.js +136 -0
- package/dist/config/fs-routes/tree-shake.d.ts +2 -0
- package/dist/config/fs-routes/tree-shake.js +357 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.js +217 -0
- package/dist/config/lazy.d.ts +3 -0
- package/dist/config/lazy.js +82 -0
- package/dist/config/manifest.d.ts +3 -0
- package/dist/config/manifest.js +74 -0
- package/dist/config/utils.d.ts +4 -0
- package/dist/config/utils.js +6 -0
- package/dist/config/vite-utils.d.ts +16 -0
- package/dist/config/vite-utils.js +81 -0
- package/dist/http/index.d.ts +84 -0
- package/dist/http/index.js +131 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.jsx +5 -5
- package/dist/middleware/index.d.ts +6 -6
- package/dist/middleware/index.js +39 -0
- package/dist/{router/FileRoutes.js → router.jsx} +5 -6
- package/dist/server/StartServer.d.ts +3 -3
- package/dist/server/StartServer.jsx +9 -63
- package/dist/server/assets/index.d.ts +2 -0
- package/dist/server/assets/index.js +52 -0
- package/dist/server/assets/render.d.ts +19 -0
- package/dist/server/{renderAsset.jsx → assets/render.jsx} +1 -1
- package/dist/server/collect-styles.d.ts +3 -0
- package/dist/server/collect-styles.js +69 -0
- package/dist/server/fetchEvent.d.ts +4 -3
- package/dist/server/fetchEvent.js +12 -74
- package/dist/server/fetchEvent.spec.js +18 -197
- package/dist/server/handler.d.ts +6 -12
- package/dist/server/handler.js +180 -97
- package/dist/server/index.d.ts +8 -6
- package/dist/server/index.jsx +14 -6
- package/dist/server/manifest/client-manifest.d.ts +9 -0
- package/dist/server/manifest/client-manifest.js +6 -0
- package/dist/server/manifest/dev-client-manifest.d.ts +4 -0
- package/dist/server/manifest/dev-client-manifest.js +24 -0
- package/dist/server/manifest/dev-ssr-manifest.d.ts +5 -0
- package/dist/server/manifest/dev-ssr-manifest.js +23 -0
- package/dist/server/manifest/prod-client-manifest.d.ts +5 -0
- package/dist/server/manifest/prod-client-manifest.js +26 -0
- package/dist/server/manifest/prod-ssr-manifest.d.ts +6 -0
- package/dist/server/manifest/prod-ssr-manifest.js +90 -0
- package/dist/server/manifest/ssr-manifest.d.ts +4 -0
- package/dist/server/manifest/ssr-manifest.js +6 -0
- package/dist/{router → server}/routes.d.ts +5 -10
- package/dist/{router → server}/routes.js +35 -36
- package/dist/{runtime → server}/server-fns-runtime.d.ts +1 -1
- package/dist/{runtime → server}/server-fns-runtime.js +7 -6
- package/dist/server/server-functions-handler.d.ts +2 -0
- package/dist/{runtime/server-handler.js → server/server-functions-handler.js} +65 -100
- package/dist/server/server-runtime.d.ts +3 -0
- package/dist/{runtime → server}/server-runtime.js +9 -16
- package/dist/server/spa/StartServer.d.ts +1 -1
- package/dist/server/spa/StartServer.jsx +7 -9
- package/dist/server/spa/handler.d.ts +3 -3
- package/dist/server/spa/handler.js +9 -11
- package/dist/server/spa/index.d.ts +4 -3
- package/dist/server/spa/index.jsx +4 -3
- package/dist/server/types.d.ts +7 -9
- package/dist/server/util.d.ts +2 -0
- package/dist/server/util.js +8 -0
- package/dist/shared/ErrorBoundary.jsx +2 -2
- package/dist/shared/HttpHeader.jsx +4 -2
- package/dist/shared/{HttpStatusCode.jsx → HttpStatusCode.js} +3 -1
- package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +2 -2
- package/dist/shared/dev-overlay/DevOverlayDialog.jsx +75 -66
- package/dist/shared/dev-overlay/createStackFrame.js +3 -3
- package/dist/shared/dev-overlay/index.jsx +5 -8
- package/dist/shared/lazy.d.ts +3 -0
- package/dist/shared/lazy.js +40 -0
- package/dist/shared/serverFunction.d.ts +1 -1
- package/package.json +45 -67
- package/scripts/build.js +15 -0
- package/scripts/validate-imports.js +316 -0
- package/src/client/StartClient.tsx +34 -0
- package/src/client/index.tsx +2 -0
- package/src/client/mount.ts +114 -0
- package/src/client/spa/index.tsx +9 -0
- package/src/config/constants.ts +19 -0
- package/src/config/dev-server.ts +149 -0
- package/src/config/fs-router.ts +177 -0
- package/src/config/fs-routes/fs-watcher.ts +81 -0
- package/src/config/fs-routes/index.ts +138 -0
- package/src/config/fs-routes/router.ts +169 -0
- package/src/config/fs-routes/tree-shake.ts +392 -0
- package/src/config/index.ts +236 -0
- package/src/config/lazy.ts +100 -0
- package/src/config/manifest.ts +84 -0
- package/src/config/utils.ts +5 -0
- package/src/config/vite-utils.ts +113 -0
- package/src/env.d.ts +35 -0
- package/src/http/index.ts +253 -0
- package/src/index.tsx +19 -0
- package/src/internal.d.ts +14 -0
- package/src/middleware/index.ts +82 -0
- package/src/router.tsx +36 -0
- package/src/server/StartServer.tsx +62 -0
- package/src/server/assets/index.ts +70 -0
- package/src/server/assets/render.tsx +42 -0
- package/src/server/collect-styles.ts +94 -0
- package/src/server/fetchEvent.spec.ts +89 -0
- package/src/server/fetchEvent.ts +36 -0
- package/src/server/handler.ts +250 -0
- package/src/server/index.tsx +16 -0
- package/src/server/manifest/client-manifest.ts +8 -0
- package/src/server/manifest/dev-client-manifest.ts +19 -0
- package/src/server/manifest/dev-ssr-manifest.ts +21 -0
- package/src/server/manifest/prod-client-manifest.ts +18 -0
- package/src/server/manifest/prod-ssr-manifest.ts +125 -0
- package/src/server/manifest/ssr-manifest.ts +8 -0
- package/src/server/routes.ts +138 -0
- package/src/server/server-fns-runtime.ts +31 -0
- package/src/server/server-functions-handler.ts +364 -0
- package/src/server/server-runtime.ts +240 -0
- package/src/server/spa/StartServer.tsx +40 -0
- package/src/server/spa/handler.ts +29 -0
- package/src/server/spa/index.tsx +5 -0
- package/src/server/types.ts +82 -0
- package/src/server/util.ts +12 -0
- package/src/shared/ErrorBoundary.tsx +52 -0
- package/src/shared/GET.ts +8 -0
- package/src/shared/HttpHeader.tsx +42 -0
- package/src/shared/HttpStatusCode.ts +27 -0
- package/src/shared/clientOnly.ts +44 -0
- package/src/shared/dev-overlay/CodeView.tsx +95 -0
- package/src/shared/dev-overlay/DevOverlayDialog.tsx +316 -0
- package/src/shared/dev-overlay/createStackFrame.ts +77 -0
- package/src/shared/dev-overlay/download.ts +6 -0
- package/src/shared/dev-overlay/env.d.ts +4 -0
- package/src/shared/dev-overlay/get-source-map.ts +35 -0
- package/src/shared/dev-overlay/icons.tsx +288 -0
- package/src/shared/dev-overlay/index.tsx +63 -0
- package/src/shared/dev-overlay/styles.css +292 -0
- package/src/shared/lazy.ts +51 -0
- package/src/shared/serverFunction.ts +10 -0
- package/src/virtual.d.ts +27 -0
- package/tsconfig.json +23 -0
- package/vitest.config.ts +9 -0
- package/config/fs-router.js +0 -142
- package/config/index.d.ts +0 -40
- package/config/index.js +0 -304
- package/config/server-components.js +0 -106
- package/dist/client/islands.d.ts +0 -7
- package/dist/client/islands.jsx +0 -10
- package/dist/middleware/index.jsx +0 -35
- package/dist/router/index.d.ts +0 -1
- package/dist/router/index.jsx +0 -2
- package/dist/router/lazyRoute.d.ts +0 -6
- package/dist/router/lazyRoute.js +0 -53
- package/dist/runtime/server-handler.d.ts +0 -2
- package/dist/runtime/server-runtime.d.ts +0 -3
- package/dist/server/islands/index.d.ts +0 -19
- package/dist/server/islands/index.jsx +0 -62
- package/dist/server/islands/utils.d.ts +0 -1
- package/dist/server/islands/utils.jsx +0 -85
- package/dist/server/pageEvent.d.ts +0 -2
- package/dist/server/pageEvent.js +0 -56
- package/dist/server/renderAsset.d.ts +0 -2
- package/env.d.ts +0 -26
- /package/dist/{router/FileRoutes.d.ts → router.d.ts} +0 -0
- /package/dist/shared/{clientOnly.jsx → clientOnly.js} +0 -0
- /package/dist/shared/{serverFunction.jsx → serverFunction.js} +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { join } from "pathe";
|
|
10
|
+
export function getClientDevManifest() {
|
|
11
|
+
return {
|
|
12
|
+
import(id) {
|
|
13
|
+
return import(__rewriteRelativeImportExtension(/* @vite-ignore */ join("/", id), true));
|
|
14
|
+
},
|
|
15
|
+
async getAssets(id) {
|
|
16
|
+
const assetsPath = `/@manifest/client/${Date.now()}/assets?id=${id}`;
|
|
17
|
+
const assets = (await import(__rewriteRelativeImportExtension(/* @vite-ignore */ assetsPath, true))).default;
|
|
18
|
+
return await Promise.all(assets.map(async (v) => ({
|
|
19
|
+
...v,
|
|
20
|
+
children: await v.children()
|
|
21
|
+
})));
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { join, normalize } from "pathe";
|
|
10
|
+
export function getSsrDevManifest(environment) {
|
|
11
|
+
return {
|
|
12
|
+
path: (id) => normalize(join(import.meta.env.BASE_URL, id)),
|
|
13
|
+
async getAssets(id) {
|
|
14
|
+
const assetsPath = `/@manifest/${environment}/${Date.now()}/assets?id=${id}`;
|
|
15
|
+
const assets = (await import(__rewriteRelativeImportExtension(/* @vite-ignore */ assetsPath, true))).default;
|
|
16
|
+
return await Promise.all(assets.map(async (v) => ({
|
|
17
|
+
...v,
|
|
18
|
+
children: await v.children()
|
|
19
|
+
})));
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export { getSsrDevManifest as getSsrManifest };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
export function getClientProdManifest() {
|
|
10
|
+
return {
|
|
11
|
+
import(id) {
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
return import(__rewriteRelativeImportExtension(/* @vite-ignore */ window.manifest[id].output, true));
|
|
14
|
+
},
|
|
15
|
+
async getAssets(id) {
|
|
16
|
+
if (id.startsWith("./"))
|
|
17
|
+
id = id.slice(2);
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
return window.manifest[id]?.assets ?? [];
|
|
20
|
+
},
|
|
21
|
+
async json() {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
return window.manifest;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { clientViteManifest } from "solid-start:client-vite-manifest";
|
|
2
|
+
import { join } from "pathe";
|
|
3
|
+
// Only reads from client manifest atm, might need server support for islands
|
|
4
|
+
export function getSsrProdManifest() {
|
|
5
|
+
const viteManifest = clientViteManifest;
|
|
6
|
+
return {
|
|
7
|
+
path(id) {
|
|
8
|
+
if (id.startsWith("./"))
|
|
9
|
+
id = id.slice(2);
|
|
10
|
+
const viteManifestEntry = clientViteManifest[id /*import.meta.env.START_CLIENT_ENTRY*/];
|
|
11
|
+
if (!viteManifestEntry)
|
|
12
|
+
throw new Error(`No entry found in vite manifest for '${id}'`);
|
|
13
|
+
return join("/", viteManifestEntry.file);
|
|
14
|
+
},
|
|
15
|
+
async getAssets(id) {
|
|
16
|
+
if (id.startsWith("./"))
|
|
17
|
+
id = id.slice(2);
|
|
18
|
+
return createHtmlTagsForAssets(findAssetsInViteManifest(clientViteManifest, id));
|
|
19
|
+
},
|
|
20
|
+
async json() {
|
|
21
|
+
const json = {};
|
|
22
|
+
const entryKeys = Object.keys(viteManifest)
|
|
23
|
+
.filter((id) => viteManifest[id]?.isEntry || viteManifest[id]?.isDynamicEntry)
|
|
24
|
+
.map((id) => id);
|
|
25
|
+
for (const entryKey of entryKeys) {
|
|
26
|
+
json[entryKey] = {
|
|
27
|
+
output: join("/", viteManifest[entryKey].file),
|
|
28
|
+
assets: await this.getAssets(entryKey),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return json;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function createHtmlTagsForAssets(assets) {
|
|
36
|
+
return assets
|
|
37
|
+
.filter((asset) => asset.endsWith(".css") ||
|
|
38
|
+
asset.endsWith(".js") ||
|
|
39
|
+
asset.endsWith(".ts") ||
|
|
40
|
+
asset.endsWith(".mjs"))
|
|
41
|
+
.map((asset) => ({
|
|
42
|
+
tag: "link",
|
|
43
|
+
attrs: {
|
|
44
|
+
href: '/' + asset,
|
|
45
|
+
key: asset,
|
|
46
|
+
...(asset.endsWith(".css")
|
|
47
|
+
? { rel: "stylesheet" }
|
|
48
|
+
: { rel: "modulepreload" }),
|
|
49
|
+
},
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
const entryId = import.meta.env.START_CLIENT_ENTRY.slice(2);
|
|
53
|
+
let entryImports = undefined;
|
|
54
|
+
function findAssetsInViteManifest(manifest, id, assetMap = new Map(), stack = []) {
|
|
55
|
+
if (stack.includes(id)) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
const cached = assetMap.get(id);
|
|
59
|
+
if (cached) {
|
|
60
|
+
return cached;
|
|
61
|
+
}
|
|
62
|
+
const chunk = manifest[id];
|
|
63
|
+
if (!chunk) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
if (!entryImports) {
|
|
67
|
+
entryImports = [
|
|
68
|
+
entryId,
|
|
69
|
+
...(manifest[entryId]?.imports ?? [])
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
// Only include entry imports, if we are specifically crawling the entry
|
|
73
|
+
// Chunks (e.g. routes) that import something from entry, should not render entry css redundantly
|
|
74
|
+
const excludeEntryImports = id !== entryId;
|
|
75
|
+
const assets = chunk.css?.filter(Boolean) || [];
|
|
76
|
+
if (chunk.imports) {
|
|
77
|
+
stack.push(id);
|
|
78
|
+
for (let i = 0, l = chunk.imports.length; i < l; i++) {
|
|
79
|
+
const importId = chunk.imports[i];
|
|
80
|
+
if (!importId || (excludeEntryImports && entryImports.includes(importId)))
|
|
81
|
+
continue;
|
|
82
|
+
assets.push(...findAssetsInViteManifest(manifest, importId, assetMap, stack));
|
|
83
|
+
}
|
|
84
|
+
stack.pop();
|
|
85
|
+
}
|
|
86
|
+
assets.push(chunk.file);
|
|
87
|
+
const all = Array.from(new Set(assets));
|
|
88
|
+
assetMap.set(id, all);
|
|
89
|
+
return all;
|
|
90
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { getSsrDevManifest } from "./dev-ssr-manifest.ts";
|
|
2
|
+
import { getSsrProdManifest } from "./prod-ssr-manifest.ts";
|
|
3
|
+
export declare function getSsrManifest(target: "client" | "ssr"): ReturnType<typeof getSsrDevManifest> | ReturnType<typeof getSsrProdManifest>;
|
|
4
|
+
export { getSsrManifest as getManifest };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getSsrDevManifest } from "./dev-ssr-manifest.js";
|
|
2
|
+
import { getSsrProdManifest } from "./prod-ssr-manifest.js";
|
|
3
|
+
export function getSsrManifest(target) {
|
|
4
|
+
return import.meta.env.DEV ? getSsrDevManifest(target) : getSsrProdManifest();
|
|
5
|
+
}
|
|
6
|
+
export { getSsrManifest as getManifest };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FetchEvent } from "./types.ts";
|
|
1
2
|
interface Route {
|
|
2
3
|
path: string;
|
|
3
4
|
id: string;
|
|
@@ -11,18 +12,12 @@ interface Route {
|
|
|
11
12
|
$PATCH?: any;
|
|
12
13
|
$DELETE?: any;
|
|
13
14
|
}
|
|
14
|
-
declare module "vinxi/routes" {
|
|
15
|
-
interface Register {
|
|
16
|
-
route: {
|
|
17
|
-
path: string;
|
|
18
|
-
children?: Route[];
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
15
|
export declare const pageRoutes: Route[];
|
|
23
16
|
export declare function matchAPIRoute(path: string, method: string): {
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
params?: Record<string, any>;
|
|
18
|
+
handler: {
|
|
19
|
+
import: () => Promise<Record<string, (e: FetchEvent) => Promise<any>>>;
|
|
20
|
+
};
|
|
26
21
|
isPage: boolean;
|
|
27
22
|
} | undefined;
|
|
28
23
|
export {};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
// @ts-expect-error
|
|
2
|
+
import fileRoutes from "solid-start:routes";
|
|
1
3
|
import { createRouter } from "radix3";
|
|
2
|
-
|
|
3
|
-
export const pageRoutes = defineRoutes(fileRoutes.filter(o => o.page));
|
|
4
|
+
export const pageRoutes = defineRoutes(fileRoutes.filter((o) => o.page));
|
|
4
5
|
function defineRoutes(fileRoutes) {
|
|
5
6
|
function processRoute(routes, route, id, full) {
|
|
6
|
-
const parentRoute = Object.values(routes).find(o => {
|
|
7
|
+
const parentRoute = Object.values(routes).find((o) => {
|
|
7
8
|
return id.startsWith(o.id + "/");
|
|
8
9
|
});
|
|
9
10
|
if (!parentRoute) {
|
|
10
11
|
routes.push({
|
|
11
12
|
...route,
|
|
12
13
|
id,
|
|
13
|
-
path: id.replace(/\([^)/]+\)/g, "").replace(/\/+/g, "/")
|
|
14
|
+
path: id.replace(/\([^)/]+\)/g, "").replace(/\/+/g, "/"),
|
|
14
15
|
});
|
|
15
16
|
return routes;
|
|
16
17
|
}
|
|
@@ -23,45 +24,16 @@ function defineRoutes(fileRoutes) {
|
|
|
23
24
|
return processRoute(prevRoutes, route, route.path, route.path);
|
|
24
25
|
}, []);
|
|
25
26
|
}
|
|
26
|
-
export function matchAPIRoute(path, method) {
|
|
27
|
-
const match = router.lookup(path);
|
|
28
|
-
if (match && match.route) {
|
|
29
|
-
const route = match.route;
|
|
30
|
-
// Find the appropriate handler for the HTTP method
|
|
31
|
-
const handler = method === "HEAD"
|
|
32
|
-
? route.$HEAD || route.$GET
|
|
33
|
-
: route[`$${method}`];
|
|
34
|
-
if (handler === undefined)
|
|
35
|
-
return;
|
|
36
|
-
// Check if this is a page route
|
|
37
|
-
const isPage = route.page === true && route.$component !== undefined;
|
|
38
|
-
// Return comprehensive route information
|
|
39
|
-
return {
|
|
40
|
-
handler,
|
|
41
|
-
params: match.params,
|
|
42
|
-
isPage
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
function containsHTTP(route) {
|
|
48
|
-
return (route["$HEAD"] ||
|
|
49
|
-
route["$GET"] ||
|
|
50
|
-
route["$POST"] ||
|
|
51
|
-
route["$PUT"] ||
|
|
52
|
-
route["$PATCH"] ||
|
|
53
|
-
route["$DELETE"]);
|
|
54
|
-
}
|
|
55
27
|
const router = createRouter({
|
|
56
28
|
routes: fileRoutes.reduce((memo, route) => {
|
|
57
29
|
if (!containsHTTP(route))
|
|
58
30
|
return memo;
|
|
59
|
-
|
|
31
|
+
const path = route.path
|
|
60
32
|
.replace(/\([^)/]+\)/g, "")
|
|
61
33
|
.replace(/\/+/g, "/")
|
|
62
34
|
.replace(/\*([^/]*)/g, (_, m) => `**:${m}`)
|
|
63
35
|
.split("/")
|
|
64
|
-
.map(s =>
|
|
36
|
+
.map((s) => s.startsWith(":") || s.startsWith("*") ? s : encodeURIComponent(s))
|
|
65
37
|
.join("/");
|
|
66
38
|
if (/:[^/]*\?/g.test(path)) {
|
|
67
39
|
throw new Error(`Optional parameters are not supported in API routes: ${path}`);
|
|
@@ -71,5 +43,32 @@ const router = createRouter({
|
|
|
71
43
|
}
|
|
72
44
|
memo[path] = { route };
|
|
73
45
|
return memo;
|
|
74
|
-
}, {})
|
|
46
|
+
}, {}),
|
|
75
47
|
});
|
|
48
|
+
function containsHTTP(route) {
|
|
49
|
+
return (route["$HEAD"] ||
|
|
50
|
+
route["$GET"] ||
|
|
51
|
+
route["$POST"] ||
|
|
52
|
+
route["$PUT"] ||
|
|
53
|
+
route["$PATCH"] ||
|
|
54
|
+
route["$DELETE"]);
|
|
55
|
+
}
|
|
56
|
+
export function matchAPIRoute(path, method) {
|
|
57
|
+
const match = router.lookup(path);
|
|
58
|
+
if (match && match.route) {
|
|
59
|
+
const route = match.route;
|
|
60
|
+
// Find the appropriate handler for the HTTP method
|
|
61
|
+
const handler = method === "HEAD" ? route.$HEAD || route.$GET : route[`$${method}`];
|
|
62
|
+
if (handler === undefined)
|
|
63
|
+
return;
|
|
64
|
+
// Check if this is a page route
|
|
65
|
+
const isPage = route.page === true && route.$component !== undefined;
|
|
66
|
+
// Return comprehensive route information
|
|
67
|
+
return {
|
|
68
|
+
handler,
|
|
69
|
+
params: match.params,
|
|
70
|
+
isPage,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createServerReference(fn: Function, id: string
|
|
1
|
+
export declare function createServerReference(fn: Function, id: string): Function;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { getRequestEvent } from "solid-js/web";
|
|
2
2
|
import { provideRequestEvent } from "solid-js/web/storage";
|
|
3
|
-
|
|
4
|
-
export function createServerReference(fn, id, name) {
|
|
3
|
+
export function createServerReference(fn, id) {
|
|
5
4
|
if (typeof fn !== "function")
|
|
6
5
|
throw new Error("Export from a 'use server' module must be a function");
|
|
7
|
-
|
|
6
|
+
let baseURL = import.meta.env.BASE_URL ?? "/";
|
|
7
|
+
if (!baseURL.endsWith("/"))
|
|
8
|
+
baseURL += "/";
|
|
8
9
|
return new Proxy(fn, {
|
|
9
10
|
get(target, prop, receiver) {
|
|
10
11
|
if (prop === "url") {
|
|
11
|
-
return `${baseURL}
|
|
12
|
+
return `${baseURL}_server?id=${encodeURIComponent(id)}`;
|
|
12
13
|
}
|
|
13
14
|
if (prop === "GET")
|
|
14
15
|
return receiver;
|
|
@@ -18,9 +19,9 @@ export function createServerReference(fn, id, name) {
|
|
|
18
19
|
const ogEvt = getRequestEvent();
|
|
19
20
|
if (!ogEvt)
|
|
20
21
|
throw new Error("Cannot call server function outside of a request");
|
|
21
|
-
const evt =
|
|
22
|
+
const evt = { ...ogEvt };
|
|
22
23
|
evt.locals.serverFunctionMeta = {
|
|
23
|
-
id
|
|
24
|
+
id
|
|
24
25
|
};
|
|
25
26
|
evt.serverOnly = true;
|
|
26
27
|
return provideRequestEvent(evt, () => {
|