@solidjs/start 1.1.7 → 1.2.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 +11 -11
- package/config/index.d.ts +1 -0
- package/config/index.js +2 -1
- package/dist/router/routes.d.ts +1 -0
- package/dist/router/routes.js +11 -2
- package/dist/runtime/server-handler.js +11 -3
- package/dist/server/fetchEvent.js +1 -1
- package/dist/server/fetchEvent.spec.d.ts +1 -0
- package/dist/server/fetchEvent.spec.js +244 -0
- package/dist/server/handler.js +2 -0
- package/package.json +7 -3
package/config/fs-router.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {analyzeModule, BaseFileSystemRouter, cleanPath} from "vinxi/fs-router";
|
|
2
2
|
|
|
3
3
|
export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
4
4
|
toPath(src) {
|
|
@@ -43,13 +43,13 @@ export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
|
43
43
|
page: true,
|
|
44
44
|
$component: {
|
|
45
45
|
src: src,
|
|
46
|
-
pick: ["default", "$css"]
|
|
46
|
+
pick: [...exports.filter(e => e.n === e.ln && e.n !== "route").map(e => e.n), "default", "$css"]
|
|
47
47
|
},
|
|
48
48
|
$$route: hasRouteConfig
|
|
49
49
|
? {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
src: src,
|
|
51
|
+
pick: ["route"]
|
|
52
|
+
}
|
|
53
53
|
: undefined,
|
|
54
54
|
path,
|
|
55
55
|
filePath: src
|
|
@@ -123,15 +123,15 @@ export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
|
123
123
|
$component:
|
|
124
124
|
!this.config.dataOnly && hasDefault
|
|
125
125
|
? {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
src: src,
|
|
127
|
+
pick: [...exports.filter(e => e.n === e.ln && e.n !== "route" && !HTTP_METHODS.includes(e.n)).map(e => e.n), "default", "$css"]
|
|
128
|
+
}
|
|
129
129
|
: undefined,
|
|
130
130
|
$$route: hasRouteConfig
|
|
131
131
|
? {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
src: src,
|
|
133
|
+
pick: ["route"]
|
|
134
|
+
}
|
|
135
135
|
: undefined,
|
|
136
136
|
...createHTTPHandlers(src, exports),
|
|
137
137
|
path,
|
package/config/index.d.ts
CHANGED
package/config/index.js
CHANGED
|
@@ -71,6 +71,7 @@ export function defineConfig(baseConfig = {}) {
|
|
|
71
71
|
let { vite = {}, ...start } = baseConfig;
|
|
72
72
|
const extensions = [...DEFAULT_EXTENSIONS, ...(start.extensions || [])];
|
|
73
73
|
start = defu(start, {
|
|
74
|
+
publicDir: "./public",
|
|
74
75
|
appRoot: "./src",
|
|
75
76
|
routeDir: "./routes",
|
|
76
77
|
ssr: true,
|
|
@@ -110,7 +111,7 @@ export function defineConfig(baseConfig = {}) {
|
|
|
110
111
|
name: "public",
|
|
111
112
|
type: "static",
|
|
112
113
|
base: "/",
|
|
113
|
-
dir:
|
|
114
|
+
dir: start.publicDir
|
|
114
115
|
},
|
|
115
116
|
{
|
|
116
117
|
name: "ssr",
|
package/dist/router/routes.d.ts
CHANGED
package/dist/router/routes.js
CHANGED
|
@@ -26,14 +26,23 @@ function defineRoutes(fileRoutes) {
|
|
|
26
26
|
export function matchAPIRoute(path, method) {
|
|
27
27
|
const match = router.lookup(path);
|
|
28
28
|
if (match && match.route) {
|
|
29
|
-
const
|
|
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}`];
|
|
30
34
|
if (handler === undefined)
|
|
31
35
|
return;
|
|
36
|
+
// Check if this is a page route
|
|
37
|
+
const isPage = route.page === true && route.$component !== undefined;
|
|
38
|
+
// Return comprehensive route information
|
|
32
39
|
return {
|
|
33
40
|
handler,
|
|
34
|
-
params: match.params
|
|
41
|
+
params: match.params,
|
|
42
|
+
isPage
|
|
35
43
|
};
|
|
36
44
|
}
|
|
45
|
+
return undefined;
|
|
37
46
|
}
|
|
38
47
|
function containsHTTP(route) {
|
|
39
48
|
return (route["$HEAD"] ||
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="vinxi/types/server" />
|
|
2
|
+
import { parseSetCookie } from "cookie-es";
|
|
2
3
|
import { crossSerializeStream, fromJSON, getCrossReferenceHeader } from "seroval";
|
|
3
4
|
// @ts-ignore
|
|
4
5
|
import { CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLPlugin, URLSearchParamsPlugin } from "seroval-plugins/web";
|
|
@@ -275,9 +276,16 @@ function createSingleFlightHeaders(sourceEvent) {
|
|
|
275
276
|
SetCookies.forEach(cookie => {
|
|
276
277
|
if (!cookie)
|
|
277
278
|
return;
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
const { maxAge, expires, name, value } = parseSetCookie(cookie);
|
|
280
|
+
if (maxAge != null && maxAge <= 0) {
|
|
281
|
+
delete cookies[name];
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (expires != null && expires.getTime() <= Date.now()) {
|
|
285
|
+
delete cookies[name];
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
cookies[name] = value;
|
|
281
289
|
});
|
|
282
290
|
Object.entries(cookies).forEach(([key, value]) => {
|
|
283
291
|
headers.append("cookie", `${key}=${value}`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { cloneEvent, createFetchEvent, getFetchEvent, mergeResponseHeaders } from "./fetchEvent";
|
|
3
|
+
vi.mock("vinxi/http", () => ({
|
|
4
|
+
getWebRequest: vi.fn(),
|
|
5
|
+
getRequestIP: vi.fn(),
|
|
6
|
+
getResponseStatus: vi.fn(),
|
|
7
|
+
setResponseStatus: vi.fn(),
|
|
8
|
+
getResponseStatusText: vi.fn(),
|
|
9
|
+
getResponseHeader: vi.fn(),
|
|
10
|
+
getResponseHeaders: vi.fn(),
|
|
11
|
+
setResponseHeader: vi.fn(),
|
|
12
|
+
appendResponseHeader: vi.fn(),
|
|
13
|
+
removeResponseHeader: vi.fn()
|
|
14
|
+
}));
|
|
15
|
+
import * as vinxiHttp from "vinxi/http";
|
|
16
|
+
const mockedVinxiHttp = vi.mocked(vinxiHttp);
|
|
17
|
+
const createMockH3Event = () => {
|
|
18
|
+
const mockRequest = new Request("http://localhost/test");
|
|
19
|
+
const mockStatus = 200;
|
|
20
|
+
const mockStatusText = "OK";
|
|
21
|
+
return {
|
|
22
|
+
node: {
|
|
23
|
+
req: {},
|
|
24
|
+
res: {
|
|
25
|
+
statusCode: mockStatus,
|
|
26
|
+
statusMessage: mockStatusText
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
context: {},
|
|
30
|
+
web: {
|
|
31
|
+
request: mockRequest
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
describe("fetchEvent", () => {
|
|
36
|
+
let mockH3Event;
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
mockH3Event = createMockH3Event();
|
|
39
|
+
vi.clearAllMocks();
|
|
40
|
+
mockedVinxiHttp.getWebRequest.mockReturnValue(mockH3Event.web?.request);
|
|
41
|
+
mockedVinxiHttp.getRequestIP.mockReturnValue("127.0.0.1");
|
|
42
|
+
mockedVinxiHttp.getResponseStatus.mockReturnValue(200);
|
|
43
|
+
mockedVinxiHttp.setResponseStatus.mockImplementation(() => { });
|
|
44
|
+
mockedVinxiHttp.getResponseStatusText.mockReturnValue("OK");
|
|
45
|
+
mockedVinxiHttp.getResponseHeader.mockReturnValue(undefined);
|
|
46
|
+
mockedVinxiHttp.getResponseHeaders.mockReturnValue({});
|
|
47
|
+
mockedVinxiHttp.setResponseHeader.mockImplementation(() => { });
|
|
48
|
+
mockedVinxiHttp.appendResponseHeader.mockImplementation(() => { });
|
|
49
|
+
mockedVinxiHttp.removeResponseHeader.mockImplementation(() => { });
|
|
50
|
+
});
|
|
51
|
+
describe("createFetchEvent", () => {
|
|
52
|
+
it("should create a FetchEvent from H3Event", () => {
|
|
53
|
+
const fetchEvent = createFetchEvent(mockH3Event);
|
|
54
|
+
expect(fetchEvent).toEqual({
|
|
55
|
+
request: mockH3Event.web?.request,
|
|
56
|
+
response: expect.any(Object),
|
|
57
|
+
clientAddress: "127.0.0.1",
|
|
58
|
+
locals: {},
|
|
59
|
+
nativeEvent: mockH3Event
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it("should create response stub with correct properties", () => {
|
|
63
|
+
const fetchEvent = createFetchEvent(mockH3Event);
|
|
64
|
+
expect(fetchEvent.response).toHaveProperty("status");
|
|
65
|
+
expect(fetchEvent.response).toHaveProperty("statusText");
|
|
66
|
+
expect(fetchEvent.response).toHaveProperty("headers");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe("cloneEvent", () => {
|
|
70
|
+
it("should create a shallow copy of FetchEvent", () => {
|
|
71
|
+
const original = createFetchEvent(mockH3Event);
|
|
72
|
+
const cloned = cloneEvent(original);
|
|
73
|
+
expect(cloned).toEqual(original);
|
|
74
|
+
expect(cloned).not.toBe(original);
|
|
75
|
+
expect(cloned.request).toBe(original.request);
|
|
76
|
+
expect(cloned.response).toBe(original.response);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe("getFetchEvent", () => {
|
|
80
|
+
it("should create and cache FetchEvent on first call", () => {
|
|
81
|
+
const fetchEvent = getFetchEvent(mockH3Event);
|
|
82
|
+
expect(mockH3Event.context.solidFetchEvent).toBe(fetchEvent);
|
|
83
|
+
expect(fetchEvent.nativeEvent).toBe(mockH3Event);
|
|
84
|
+
});
|
|
85
|
+
it("should return cached FetchEvent on subsequent calls", () => {
|
|
86
|
+
const firstCall = getFetchEvent(mockH3Event);
|
|
87
|
+
const secondCall = getFetchEvent(mockH3Event);
|
|
88
|
+
expect(firstCall).toBe(secondCall);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe("mergeResponseHeaders", () => {
|
|
92
|
+
it("should merge headers from Headers object to H3Event", () => {
|
|
93
|
+
const headers = new Headers({
|
|
94
|
+
"content-type": "application/json",
|
|
95
|
+
"x-custom": "value"
|
|
96
|
+
});
|
|
97
|
+
mergeResponseHeaders(mockH3Event, headers);
|
|
98
|
+
expect(mockedVinxiHttp.appendResponseHeader).toHaveBeenCalledWith(mockH3Event, "content-type", "application/json");
|
|
99
|
+
expect(mockedVinxiHttp.appendResponseHeader).toHaveBeenCalledWith(mockH3Event, "x-custom", "value");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe("ResponseStub", () => {
|
|
103
|
+
let fetchEvent;
|
|
104
|
+
beforeEach(() => {
|
|
105
|
+
fetchEvent = createFetchEvent(mockH3Event);
|
|
106
|
+
});
|
|
107
|
+
describe("status", () => {
|
|
108
|
+
it("should get status from H3Event", () => {
|
|
109
|
+
expect(fetchEvent.response.status).toBe(200);
|
|
110
|
+
});
|
|
111
|
+
it("should set status on H3Event", () => {
|
|
112
|
+
fetchEvent.response.status = 404;
|
|
113
|
+
expect(mockedVinxiHttp.setResponseStatus).toHaveBeenCalledWith(mockH3Event, 404);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe("statusText", () => {
|
|
117
|
+
it("should get statusText from H3Event", () => {
|
|
118
|
+
expect(fetchEvent.response.statusText).toBe("OK");
|
|
119
|
+
});
|
|
120
|
+
it("should set statusText on H3Event", () => {
|
|
121
|
+
fetchEvent.response.statusText = "Not Found";
|
|
122
|
+
expect(mockedVinxiHttp.setResponseStatus).toHaveBeenCalledWith(mockH3Event, 200, "Not Found");
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe("HeaderProxy", () => {
|
|
127
|
+
let fetchEvent;
|
|
128
|
+
beforeEach(() => {
|
|
129
|
+
fetchEvent = createFetchEvent(mockH3Event);
|
|
130
|
+
});
|
|
131
|
+
describe("get", () => {
|
|
132
|
+
it("should return null for non-existent header", () => {
|
|
133
|
+
expect(fetchEvent.response.headers.get("non-existent")).toBe(null);
|
|
134
|
+
});
|
|
135
|
+
it("should return string value for single header", () => {
|
|
136
|
+
mockedVinxiHttp.getResponseHeader.mockReturnValue("application/json");
|
|
137
|
+
expect(fetchEvent.response.headers.get("content-type")).toBe("application/json");
|
|
138
|
+
});
|
|
139
|
+
it("should join array values with comma", () => {
|
|
140
|
+
mockedVinxiHttp.getResponseHeader.mockReturnValue(["text/html", "application/json"]);
|
|
141
|
+
expect(fetchEvent.response.headers.get("accept")).toBe("text/html, application/json");
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
describe("has", () => {
|
|
145
|
+
it("should return false for non-existent header", () => {
|
|
146
|
+
mockedVinxiHttp.getResponseHeader.mockReturnValue(undefined);
|
|
147
|
+
expect(fetchEvent.response.headers.has("non-existent")).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
it("should return true for existing header", () => {
|
|
150
|
+
mockedVinxiHttp.getResponseHeader.mockReturnValue("application/json");
|
|
151
|
+
expect(fetchEvent.response.headers.has("content-type")).toBe(true);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe("set", () => {
|
|
155
|
+
it("should set header value", () => {
|
|
156
|
+
fetchEvent.response.headers.set("content-type", "application/json");
|
|
157
|
+
expect(mockedVinxiHttp.setResponseHeader).toHaveBeenCalledWith(mockH3Event, "content-type", "application/json");
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
describe("delete", () => {
|
|
161
|
+
it("should remove header", () => {
|
|
162
|
+
fetchEvent.response.headers.delete("content-type");
|
|
163
|
+
expect(mockedVinxiHttp.removeResponseHeader).toHaveBeenCalledWith(mockH3Event, "content-type");
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
describe("append", () => {
|
|
167
|
+
it("should append header value", () => {
|
|
168
|
+
fetchEvent.response.headers.append("x-custom", "value");
|
|
169
|
+
expect(mockedVinxiHttp.appendResponseHeader).toHaveBeenCalledWith(mockH3Event, "x-custom", "value");
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
describe("getSetCookie", () => {
|
|
173
|
+
it("should return array for single cookie", () => {
|
|
174
|
+
mockedVinxiHttp.getResponseHeader.mockReturnValue("session=abc123");
|
|
175
|
+
expect(fetchEvent.response.headers.getSetCookie()).toEqual(["session=abc123"]);
|
|
176
|
+
});
|
|
177
|
+
it("should return array for multiple cookies", () => {
|
|
178
|
+
mockedVinxiHttp.getResponseHeader.mockReturnValue(["session=abc123", "theme=dark"]);
|
|
179
|
+
expect(fetchEvent.response.headers.getSetCookie()).toEqual([
|
|
180
|
+
"session=abc123",
|
|
181
|
+
"theme=dark"
|
|
182
|
+
]);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
describe("forEach", () => {
|
|
186
|
+
it("should iterate over headers", () => {
|
|
187
|
+
mockedVinxiHttp.getResponseHeaders.mockReturnValue({
|
|
188
|
+
"content-type": "application/json",
|
|
189
|
+
"x-custom": ["value1", "value2"]
|
|
190
|
+
});
|
|
191
|
+
const callback = vi.fn();
|
|
192
|
+
fetchEvent.response.headers.forEach(callback);
|
|
193
|
+
expect(callback).toHaveBeenCalledWith("application/json", "content-type", expect.any(Object));
|
|
194
|
+
expect(callback).toHaveBeenCalledWith("value1, value2", "x-custom", expect.any(Object));
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
describe("entries", () => {
|
|
198
|
+
it("should return iterator of header entries", () => {
|
|
199
|
+
mockedVinxiHttp.getResponseHeaders.mockReturnValue({
|
|
200
|
+
"content-type": "application/json",
|
|
201
|
+
"x-custom": ["value1", "value2"]
|
|
202
|
+
});
|
|
203
|
+
const entries = Array.from(fetchEvent.response.headers.entries());
|
|
204
|
+
expect(entries).toEqual([
|
|
205
|
+
["content-type", "application/json"],
|
|
206
|
+
["x-custom", "value1, value2"]
|
|
207
|
+
]);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
describe("keys", () => {
|
|
211
|
+
it("should return iterator of header keys", () => {
|
|
212
|
+
mockedVinxiHttp.getResponseHeaders.mockReturnValue({
|
|
213
|
+
"content-type": "application/json",
|
|
214
|
+
"x-custom": "value"
|
|
215
|
+
});
|
|
216
|
+
const keys = Array.from(fetchEvent.response.headers.keys());
|
|
217
|
+
expect(keys).toEqual(["content-type", "x-custom"]);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
describe("values", () => {
|
|
221
|
+
it("should return iterator of header values", () => {
|
|
222
|
+
mockedVinxiHttp.getResponseHeaders.mockReturnValue({
|
|
223
|
+
"content-type": "application/json",
|
|
224
|
+
"x-custom": ["value1", "value2"]
|
|
225
|
+
});
|
|
226
|
+
const values = Array.from(fetchEvent.response.headers.values());
|
|
227
|
+
expect(values).toEqual(["application/json", "value1, value2"]);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
describe("Symbol.iterator", () => {
|
|
231
|
+
it("should be iterable", () => {
|
|
232
|
+
mockedVinxiHttp.getResponseHeaders.mockReturnValue({
|
|
233
|
+
"content-type": "application/json",
|
|
234
|
+
"x-custom": "value"
|
|
235
|
+
});
|
|
236
|
+
const entries = Array.from(fetchEvent.response.headers);
|
|
237
|
+
expect(entries).toEqual([
|
|
238
|
+
["content-type", "application/json"],
|
|
239
|
+
["x-custom", "value"]
|
|
240
|
+
]);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|
package/dist/server/handler.js
CHANGED
|
@@ -39,6 +39,8 @@ export function createBaseHandler(fn, createPageEvent, options = {}, routerLoad)
|
|
|
39
39
|
if (event.request.method !== "GET") {
|
|
40
40
|
throw new Error(`API handler for ${event.request.method} "${event.request.url}" did not return a response.`);
|
|
41
41
|
}
|
|
42
|
+
if (!match.isPage)
|
|
43
|
+
return;
|
|
42
44
|
}
|
|
43
45
|
// render
|
|
44
46
|
const context = await createPageEvent(event);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/start",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,12 +56,14 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"solid-js": "^1.9.5",
|
|
59
|
-
"vinxi": "^0.5.7"
|
|
59
|
+
"vinxi": "^0.5.7",
|
|
60
|
+
"vitest": "3.0.5"
|
|
60
61
|
},
|
|
61
62
|
"dependencies": {
|
|
62
63
|
"@tanstack/server-functions-plugin": "1.121.21",
|
|
63
64
|
"@vinxi/plugin-directives": "^0.5.0",
|
|
64
65
|
"@vinxi/server-components": "^0.5.0",
|
|
66
|
+
"cookie-es": "^2.0.0",
|
|
65
67
|
"defu": "^6.1.2",
|
|
66
68
|
"error-stack-parser": "^2.1.4",
|
|
67
69
|
"html-to-image": "^1.11.11",
|
|
@@ -79,6 +81,8 @@
|
|
|
79
81
|
},
|
|
80
82
|
"scripts": {
|
|
81
83
|
"typecheck": "tsc --noEmit",
|
|
82
|
-
"build": "node build && pnpm tsc"
|
|
84
|
+
"build": "node build && pnpm tsc",
|
|
85
|
+
"test": "vitest",
|
|
86
|
+
"test:ci": "vitest run"
|
|
83
87
|
}
|
|
84
88
|
}
|