@solidjs/start 1.0.0-rc.1 → 1.0.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/config/fs-router.js +15 -10
- package/config/index.js +13 -7
- package/dist/router/FileRoutes.js +1 -1
- package/dist/router/routes.d.ts +1 -0
- package/dist/router/routes.js +2 -2
- package/dist/runtime/server-handler.js +4 -1
- package/dist/server/StartServer.jsx +7 -6
- package/dist/server/handler.d.ts +6 -1
- package/dist/server/handler.js +18 -3
- package/dist/shared/dev-overlay/get-source-map.d.ts +0 -1
- package/package.json +1 -1
package/config/fs-router.js
CHANGED
|
@@ -24,6 +24,7 @@ export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
|
24
24
|
|
|
25
25
|
if (src.endsWith(".md") || src.endsWith(".mdx")) {
|
|
26
26
|
return {
|
|
27
|
+
page: true,
|
|
27
28
|
$component: {
|
|
28
29
|
src: src,
|
|
29
30
|
pick: ["$css"]
|
|
@@ -35,10 +36,11 @@ export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
const [_, exports] = analyzeModule(src);
|
|
38
|
-
const hasDefault = exports.find(e => e.n === "default");
|
|
39
|
-
const hasRouteConfig = exports.find(e => e.n === "route");
|
|
39
|
+
const hasDefault = !!exports.find(e => e.n === "default");
|
|
40
|
+
const hasRouteConfig = !!exports.find(e => e.n === "route");
|
|
40
41
|
if (hasDefault) {
|
|
41
42
|
return {
|
|
43
|
+
page: true,
|
|
42
44
|
$component: {
|
|
43
45
|
src: src,
|
|
44
46
|
pick: ["default", "$css"]
|
|
@@ -93,6 +95,7 @@ export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
|
93
95
|
let path = this.toPath(src);
|
|
94
96
|
if (src.endsWith(".md") || src.endsWith(".mdx")) {
|
|
95
97
|
return {
|
|
98
|
+
page: true,
|
|
96
99
|
$component: {
|
|
97
100
|
src: src,
|
|
98
101
|
pick: ["$css"]
|
|
@@ -105,16 +108,18 @@ export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
|
105
108
|
|
|
106
109
|
const [_, exports] = analyzeModule(src);
|
|
107
110
|
const hasRouteConfig = exports.find(e => e.n === "route");
|
|
108
|
-
const hasDefault = exports.find(e => e.n === "default");
|
|
109
|
-
const hasAPIRoutes = exports.find(exp => HTTP_METHODS.includes(exp.n));
|
|
111
|
+
const hasDefault = !!exports.find(e => e.n === "default");
|
|
112
|
+
const hasAPIRoutes = !!exports.find(exp => HTTP_METHODS.includes(exp.n));
|
|
110
113
|
if (hasDefault || hasAPIRoutes) {
|
|
111
114
|
return {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
page: hasDefault,
|
|
116
|
+
$component:
|
|
117
|
+
!this.config.dataOnly && hasDefault
|
|
118
|
+
? {
|
|
119
|
+
src: src,
|
|
120
|
+
pick: ["default", "$css"]
|
|
121
|
+
}
|
|
122
|
+
: undefined,
|
|
118
123
|
$$route: hasRouteConfig
|
|
119
124
|
? {
|
|
120
125
|
src: src,
|
package/config/index.js
CHANGED
|
@@ -30,7 +30,8 @@ function solidStartServerFsRouter(config) {
|
|
|
30
30
|
new SolidStartServerFileRouter(
|
|
31
31
|
{
|
|
32
32
|
dir: resolve.absolute(config.dir, router.root),
|
|
33
|
-
extensions: config.extensions ?? DEFAULT_EXTENSIONS
|
|
33
|
+
extensions: config.extensions ?? DEFAULT_EXTENSIONS,
|
|
34
|
+
dataOnly: config.dataOnly
|
|
34
35
|
},
|
|
35
36
|
router,
|
|
36
37
|
app
|
|
@@ -90,7 +91,7 @@ export function defineConfig(baseConfig = {}) {
|
|
|
90
91
|
},
|
|
91
92
|
handler: `${start.appRoot}/entry-server${entryExtension}`,
|
|
92
93
|
middleware: start.middleware,
|
|
93
|
-
routes: solidStartServerFsRouter({ dir: routeDir, extensions }),
|
|
94
|
+
routes: solidStartServerFsRouter({ dir: routeDir, extensions, dataOnly: !start.ssr }),
|
|
94
95
|
extensions,
|
|
95
96
|
target: "server",
|
|
96
97
|
plugins: async () => {
|
|
@@ -133,7 +134,9 @@ export function defineConfig(baseConfig = {}) {
|
|
|
133
134
|
},
|
|
134
135
|
cacheDir: "node_modules/.vinxi/server",
|
|
135
136
|
define: {
|
|
136
|
-
"import.meta.env.START_APP": JSON.stringify(
|
|
137
|
+
"import.meta.env.START_APP": JSON.stringify(
|
|
138
|
+
`${start.appRoot}/app${entryExtension}`
|
|
139
|
+
),
|
|
137
140
|
"import.meta.env.START_ISLANDS": JSON.stringify(start.experimental.islands),
|
|
138
141
|
"import.meta.env.SSR": JSON.stringify(true),
|
|
139
142
|
"import.meta.env.START_SSR": JSON.stringify(start.ssr),
|
|
@@ -201,7 +204,9 @@ export function defineConfig(baseConfig = {}) {
|
|
|
201
204
|
},
|
|
202
205
|
cacheDir: "node_modules/.vinxi/client",
|
|
203
206
|
define: {
|
|
204
|
-
"import.meta.env.START_APP": JSON.stringify(
|
|
207
|
+
"import.meta.env.START_APP": JSON.stringify(
|
|
208
|
+
`${start.appRoot}/app${entryExtension}`
|
|
209
|
+
),
|
|
205
210
|
"import.meta.env.START_ISLANDS": JSON.stringify(start.experimental.islands),
|
|
206
211
|
"import.meta.env.SSR": JSON.stringify(false),
|
|
207
212
|
"import.meta.env.START_SSR": JSON.stringify(start.ssr),
|
|
@@ -213,7 +218,6 @@ export function defineConfig(baseConfig = {}) {
|
|
|
213
218
|
];
|
|
214
219
|
}
|
|
215
220
|
},
|
|
216
|
-
|
|
217
221
|
{
|
|
218
222
|
name: "server-fns",
|
|
219
223
|
type: "http",
|
|
@@ -223,7 +227,7 @@ export function defineConfig(baseConfig = {}) {
|
|
|
223
227
|
),
|
|
224
228
|
middleware: start.middleware,
|
|
225
229
|
target: "server",
|
|
226
|
-
routes: solidStartServerFsRouter({ dir: routeDir, extensions }),
|
|
230
|
+
routes: solidStartServerFsRouter({ dir: routeDir, extensions, dataOnly: !start.ssr }),
|
|
227
231
|
plugins: async () => {
|
|
228
232
|
const userConfig =
|
|
229
233
|
typeof vite === "function" ? await vite({ router: "server-function" }) : { ...vite };
|
|
@@ -263,7 +267,9 @@ export function defineConfig(baseConfig = {}) {
|
|
|
263
267
|
}
|
|
264
268
|
},
|
|
265
269
|
define: {
|
|
266
|
-
"import.meta.env.START_APP": JSON.stringify(
|
|
270
|
+
"import.meta.env.START_APP": JSON.stringify(
|
|
271
|
+
`${start.appRoot}/app${entryExtension}`
|
|
272
|
+
),
|
|
267
273
|
"import.meta.env.START_ISLANDS": JSON.stringify(start.experimental.islands),
|
|
268
274
|
"import.meta.env.SSR": JSON.stringify(true),
|
|
269
275
|
"import.meta.env.START_SSR": JSON.stringify(start.ssr),
|
|
@@ -10,7 +10,7 @@ export function createRoutes() {
|
|
|
10
10
|
...(route.$$route ? route.$$route.require().route.info : {}),
|
|
11
11
|
filesystem: true
|
|
12
12
|
},
|
|
13
|
-
component: lazyRoute(route.$component, import.meta.env.START_ISLANDS
|
|
13
|
+
component: route.$component && lazyRoute(route.$component, import.meta.env.START_ISLANDS
|
|
14
14
|
? import.meta.env.MANIFEST["ssr"]
|
|
15
15
|
: import.meta.env.MANIFEST["client"], import.meta.env.MANIFEST["ssr"]),
|
|
16
16
|
children: route.children ? route.children.map(createRoute) : undefined
|
package/dist/router/routes.d.ts
CHANGED
package/dist/router/routes.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRouter } from "radix3";
|
|
2
2
|
import fileRoutes from "vinxi/routes";
|
|
3
|
-
export const pageRoutes = defineRoutes(fileRoutes.filter(o => o
|
|
3
|
+
export const pageRoutes = defineRoutes(fileRoutes.filter(o => o.page));
|
|
4
4
|
function defineRoutes(fileRoutes) {
|
|
5
5
|
function processRoute(routes, route, id, full) {
|
|
6
6
|
const parentRoute = Object.values(routes).find(o => {
|
|
@@ -21,7 +21,7 @@ function defineRoutes(fileRoutes) {
|
|
|
21
21
|
}
|
|
22
22
|
export function matchAPIRoute(path, method) {
|
|
23
23
|
const match = router.lookup(path);
|
|
24
|
-
if (match) {
|
|
24
|
+
if (match && match.route) {
|
|
25
25
|
const handler = match.route[`$${method}`];
|
|
26
26
|
if (handler === undefined)
|
|
27
27
|
return;
|
|
@@ -9,6 +9,7 @@ import { eventHandler, setHeader, setResponseStatus } from "vinxi/http";
|
|
|
9
9
|
import invariant from "vinxi/lib/invariant";
|
|
10
10
|
import { cloneEvent, getFetchEvent, mergeResponseHeaders } from "../server/fetchEvent";
|
|
11
11
|
import { createPageEvent } from "../server/pageEvent";
|
|
12
|
+
import { getExpectedRedirectStatus } from "../server/handler";
|
|
12
13
|
function createChunk(data) {
|
|
13
14
|
const encodeData = new TextEncoder().encode(data);
|
|
14
15
|
const bytes = encodeData.length;
|
|
@@ -155,11 +156,13 @@ async function handleServerFunction(h3Event) {
|
|
|
155
156
|
if (!instance) {
|
|
156
157
|
const isError = result instanceof Error;
|
|
157
158
|
let redirectUrl = new URL(request.headers.get("referer")).toString();
|
|
159
|
+
let statusCode = 302;
|
|
158
160
|
if (result instanceof Response && result.headers.has("Location")) {
|
|
159
161
|
redirectUrl = new URL(result.headers.get("Location"), new URL(request.url).origin + import.meta.env.SERVER_BASE_URL).toString();
|
|
162
|
+
statusCode = getExpectedRedirectStatus(result);
|
|
160
163
|
}
|
|
161
164
|
return new Response(null, {
|
|
162
|
-
status:
|
|
165
|
+
status: statusCode,
|
|
163
166
|
headers: {
|
|
164
167
|
Location: redirectUrl,
|
|
165
168
|
...(result
|
|
@@ -26,8 +26,9 @@ export function StartServer(props) {
|
|
|
26
26
|
const context = getRequestEvent();
|
|
27
27
|
// @ts-ignore
|
|
28
28
|
const nonce = context.nonce;
|
|
29
|
-
let assets
|
|
29
|
+
let assets;
|
|
30
30
|
Promise.resolve().then(async () => {
|
|
31
|
+
let assetPromises = [];
|
|
31
32
|
// @ts-ignore
|
|
32
33
|
if (context.router && context.router.matches) {
|
|
33
34
|
// @ts-ignore
|
|
@@ -40,18 +41,18 @@ export function StartServer(props) {
|
|
|
40
41
|
const segment = matched[i];
|
|
41
42
|
const part = import.meta.env.MANIFEST[import.meta.env.START_ISLANDS ? "ssr" : "client"]
|
|
42
43
|
.inputs[segment["$component"].src];
|
|
43
|
-
|
|
44
|
-
assets.push.apply(assets, asset);
|
|
44
|
+
assetPromises.push(part.assets());
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
else
|
|
47
|
+
else if (import.meta.env.DEV)
|
|
48
48
|
console.warn("No route matched for preloading js assets");
|
|
49
49
|
}
|
|
50
|
+
assets = await Promise.all(assetPromises).then(a =>
|
|
50
51
|
// dedupe assets
|
|
51
|
-
|
|
52
|
+
[...new Map(a.flat().map(item => [item.attrs.key, item])).values()].filter(asset => import.meta.env.START_ISLANDS
|
|
52
53
|
? false
|
|
53
54
|
: asset.attrs.rel === "modulepreload" &&
|
|
54
|
-
!context.assets.find((a) => a.attrs.key === asset.attrs.key));
|
|
55
|
+
!context.assets.find((a) => a.attrs.key === asset.attrs.key)));
|
|
55
56
|
});
|
|
56
57
|
useAssets(() => (assets.length ? assets.map(m => renderAsset(m)) : undefined));
|
|
57
58
|
return (<NoHydration>
|
package/dist/server/handler.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import type { FetchEvent, HandlerOptions, PageEvent } from "./types";
|
|
1
|
+
import type { FetchEvent, HandlerOptions, PageEvent, ResponseStub } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Checks if user has set a redirect status in the response.
|
|
4
|
+
* If not, falls back to the 302 (temporary redirect)
|
|
5
|
+
*/
|
|
6
|
+
export declare function getExpectedRedirectStatus(response: ResponseStub): number;
|
|
2
7
|
export declare function createBaseHandler(fn: (context: PageEvent) => unknown, createPageEvent: (event: FetchEvent) => Promise<PageEvent>, options?: HandlerOptions | ((context: PageEvent) => HandlerOptions | Promise<HandlerOptions>)): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
3
8
|
export declare function createHandler(fn: (context: PageEvent) => unknown, options?: HandlerOptions | ((context: PageEvent) => HandlerOptions | Promise<HandlerOptions>)): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
package/dist/server/handler.js
CHANGED
|
@@ -5,6 +5,18 @@ import { eventHandler, sendRedirect, setHeader, setResponseStatus } from "vinxi/
|
|
|
5
5
|
import { matchAPIRoute } from "../router/routes";
|
|
6
6
|
import { getFetchEvent } from "./fetchEvent";
|
|
7
7
|
import { createPageEvent } from "./pageEvent";
|
|
8
|
+
// according to https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages
|
|
9
|
+
const validRedirectStatuses = new Set([301, 302, 303, 307, 308]);
|
|
10
|
+
/**
|
|
11
|
+
* Checks if user has set a redirect status in the response.
|
|
12
|
+
* If not, falls back to the 302 (temporary redirect)
|
|
13
|
+
*/
|
|
14
|
+
export function getExpectedRedirectStatus(response) {
|
|
15
|
+
if (response.status && validRedirectStatuses.has(response.status)) {
|
|
16
|
+
return response.status;
|
|
17
|
+
}
|
|
18
|
+
return 302;
|
|
19
|
+
}
|
|
8
20
|
export function createBaseHandler(fn, createPageEvent, options = {}) {
|
|
9
21
|
return eventHandler({
|
|
10
22
|
handler: (e) => {
|
|
@@ -39,7 +51,8 @@ export function createBaseHandler(fn, createPageEvent, options = {}) {
|
|
|
39
51
|
}, resolvedOptions);
|
|
40
52
|
context.complete = true;
|
|
41
53
|
if (context.response && context.response.headers.get("Location")) {
|
|
42
|
-
|
|
54
|
+
const status = getExpectedRedirectStatus(context.response);
|
|
55
|
+
return sendRedirect(e, context.response.headers.get("Location"), status);
|
|
43
56
|
}
|
|
44
57
|
return html;
|
|
45
58
|
}
|
|
@@ -66,7 +79,8 @@ export function createBaseHandler(fn, createPageEvent, options = {}) {
|
|
|
66
79
|
return fn(context);
|
|
67
80
|
}, resolvedOptions);
|
|
68
81
|
if (context.response && context.response.headers.get("Location")) {
|
|
69
|
-
|
|
82
|
+
const status = getExpectedRedirectStatus(context.response);
|
|
83
|
+
return sendRedirect(e, context.response.headers.get("Location"), status);
|
|
70
84
|
}
|
|
71
85
|
if (mode === "async")
|
|
72
86
|
return stream;
|
|
@@ -81,7 +95,8 @@ export function createBaseHandler(fn, createPageEvent, options = {}) {
|
|
|
81
95
|
function handleShellCompleteRedirect(context, e) {
|
|
82
96
|
return () => {
|
|
83
97
|
if (context.response && context.response.headers.get("Location")) {
|
|
84
|
-
|
|
98
|
+
const status = getExpectedRedirectStatus(context.response);
|
|
99
|
+
setResponseStatus(e, status);
|
|
85
100
|
setHeader(e, "Location", context.response.headers.get("Location"));
|
|
86
101
|
}
|
|
87
102
|
};
|