@solidjs/start 2.0.0-alpha.0 → 2.0.0-alpha.1
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/CHANGELOG.md +14 -0
- package/dist/client/mount.d.ts +1 -7
- package/dist/client/mount.js +1 -99
- package/dist/config/constants.js +2 -2
- package/dist/config/fs-router.js +10 -22
- package/dist/config/fs-routes/fs-watcher.js +4 -4
- package/dist/config/fs-routes/index.js +4 -6
- package/dist/config/fs-routes/router.js +5 -5
- package/dist/config/fs-routes/tree-shake.js +12 -21
- package/dist/config/index.js +33 -36
- package/dist/config/lazy.js +9 -9
- package/dist/config/manifest.js +1 -1
- package/dist/http/index.d.ts +1 -4
- package/dist/http/index.js +3 -5
- package/dist/index.d.ts +0 -1
- package/dist/router.jsx +2 -2
- package/dist/server/assets/index.js +1 -1
- package/dist/server/assets/render.jsx +2 -2
- package/dist/server/fetchEvent.spec.js +1 -1
- package/dist/server/handler.js +29 -15
- package/dist/server/index.d.ts +1 -0
- package/dist/server/manifest/dev-client-manifest.js +1 -1
- package/dist/server/manifest/dev-ssr-manifest.js +1 -1
- package/dist/server/manifest/prod-ssr-manifest.js +7 -12
- package/dist/server/routes.js +3 -3
- package/dist/server/server-fns-runtime.js +2 -2
- package/dist/server/server-functions-handler.js +6 -11
- package/dist/server/server-runtime.js +8 -8
- package/dist/shared/dev-overlay/CodeView.d.ts +1 -1
- package/dist/shared/dev-overlay/CodeView.jsx +23 -34
- package/dist/shared/dev-overlay/DevOverlayDialog.jsx +4 -4
- package/dist/shared/dev-overlay/get-source-map.d.ts +1 -1
- package/dist/shared/dev-overlay/get-source-map.js +5 -5
- package/dist/shared/dev-overlay/icons.d.ts +10 -10
- package/dist/shared/dev-overlay/icons.jsx +91 -91
- package/dist/shared/dev-overlay/index.jsx +1 -1
- package/dist/shared/lazy.js +4 -2
- package/env.d.ts +9 -0
- package/package.json +5 -4
- package/scripts/build.js +3 -3
- package/scripts/validate-imports.js +8 -8
- package/src/client/mount.ts +1 -114
- package/src/config/constants.ts +3 -3
- package/src/config/dev-server.ts +95 -99
- package/src/config/fs-router.ts +140 -155
- package/src/config/fs-routes/fs-watcher.ts +57 -61
- package/src/config/fs-routes/index.ts +117 -119
- package/src/config/fs-routes/router.ts +7 -7
- package/src/config/fs-routes/tree-shake.ts +342 -363
- package/src/config/index.ts +36 -39
- package/src/config/lazy.ts +13 -13
- package/src/config/manifest.ts +5 -5
- package/src/config/vite-utils.ts +2 -6
- package/src/env.d.ts +10 -28
- package/src/http/index.ts +105 -142
- package/src/index.tsx +0 -12
- package/src/internal.d.ts +1 -1
- package/src/middleware/index.ts +39 -49
- package/src/router.tsx +4 -3
- package/src/server/StartServer.tsx +1 -7
- package/src/server/assets/index.ts +1 -1
- package/src/server/assets/render.tsx +6 -2
- package/src/server/collect-styles.ts +63 -70
- package/src/server/fetchEvent.spec.ts +71 -75
- package/src/server/fetchEvent.ts +17 -17
- package/src/server/handler.ts +136 -129
- package/src/server/index.tsx +13 -0
- package/src/server/manifest/client-manifest.ts +1 -1
- package/src/server/manifest/dev-client-manifest.ts +7 -5
- package/src/server/manifest/dev-ssr-manifest.ts +8 -6
- package/src/server/manifest/prod-client-manifest.ts +7 -4
- package/src/server/manifest/prod-ssr-manifest.ts +78 -94
- package/src/server/manifest/ssr-manifest.ts +4 -2
- package/src/server/routes.ts +96 -108
- package/src/server/server-fns-runtime.ts +3 -3
- package/src/server/server-functions-handler.ts +294 -319
- package/src/server/server-runtime.ts +13 -13
- package/src/server/spa/handler.ts +12 -12
- package/src/server/types.ts +46 -46
- package/src/server/util.ts +4 -4
- package/src/shared/ErrorBoundary.tsx +1 -1
- package/src/shared/HttpHeader.tsx +20 -20
- package/src/shared/HttpStatusCode.ts +14 -14
- package/src/shared/clientOnly.ts +3 -3
- package/src/shared/dev-overlay/CodeView.tsx +43 -46
- package/src/shared/dev-overlay/DevOverlayDialog.tsx +4 -4
- package/src/shared/dev-overlay/createStackFrame.ts +59 -62
- package/src/shared/dev-overlay/env.d.ts +2 -2
- package/src/shared/dev-overlay/get-source-map.ts +5 -7
- package/src/shared/dev-overlay/icons.tsx +289 -121
- package/src/shared/dev-overlay/index.tsx +1 -1
- package/src/shared/lazy.ts +4 -3
- package/src/shared/serverFunction.ts +1 -1
- package/src/virtual.d.ts +10 -10
- package/tsconfig.json +2 -2
- package/vitest.config.ts +2 -2
package/src/http/index.ts
CHANGED
|
@@ -3,121 +3,105 @@ import * as h3 from "h3";
|
|
|
3
3
|
import { getRequestEvent } from "solid-js/web";
|
|
4
4
|
|
|
5
5
|
function _setContext(event: H3Event, key: string, value: any) {
|
|
6
|
-
|
|
6
|
+
event.context[key] = value;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
function _getContext(event: H3Event, key: string) {
|
|
10
|
-
|
|
10
|
+
return event.context[key];
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function getEvent() {
|
|
14
|
-
|
|
14
|
+
return getRequestEvent()!.nativeEvent;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function getWebRequest(): Request {
|
|
18
|
-
|
|
18
|
+
return getEvent().req;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const HTTPEventSymbol = Symbol("$HTTPEvent");
|
|
22
22
|
|
|
23
|
-
export function isEvent(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
);
|
|
32
|
-
// Implement logic to check if obj is an H3Event
|
|
23
|
+
export function isEvent(obj: any): obj is h3.H3Event | { [HTTPEventSymbol]: h3.H3Event } {
|
|
24
|
+
return (
|
|
25
|
+
typeof obj === "object" &&
|
|
26
|
+
(obj instanceof h3.H3Event ||
|
|
27
|
+
obj?.[HTTPEventSymbol] instanceof h3.H3Event ||
|
|
28
|
+
obj?.__is_event__ === true)
|
|
29
|
+
);
|
|
30
|
+
// Implement logic to check if obj is an H3Event
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
type Tail<T> = T extends [any, ...infer U] ? U : never;
|
|
36
34
|
|
|
37
35
|
type PrependOverload<
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
TOriginal extends (...args: Array<any>) => any,
|
|
37
|
+
TOverload extends (...args: Array<any>) => any,
|
|
40
38
|
> = TOverload & TOriginal;
|
|
41
39
|
|
|
42
40
|
// add an overload to the function without the event argument
|
|
43
41
|
type WrapFunction<TFn extends (...args: Array<any>) => any> = PrependOverload<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
? TArgs
|
|
51
|
-
: Parameters<TFn>
|
|
52
|
-
) => ReturnType<TFn>
|
|
42
|
+
TFn,
|
|
43
|
+
(
|
|
44
|
+
...args: Parameters<TFn> extends [h3.HTTPEvent<any> | h3.H3Event<any>, ...infer TArgs]
|
|
45
|
+
? TArgs
|
|
46
|
+
: Parameters<TFn>
|
|
47
|
+
) => ReturnType<TFn>
|
|
53
48
|
>;
|
|
54
49
|
|
|
55
50
|
function createWrapperFunction<TFn extends (...args: Array<any>) => any>(
|
|
56
|
-
|
|
51
|
+
h3Function: TFn,
|
|
57
52
|
): WrapFunction<TFn> {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return (h3Function as any)(...args);
|
|
70
|
-
}) as any;
|
|
53
|
+
return ((...args: Array<any>) => {
|
|
54
|
+
const event = args[0];
|
|
55
|
+
if (!isEvent(event)) {
|
|
56
|
+
args.unshift(getEvent());
|
|
57
|
+
} else {
|
|
58
|
+
args[0] =
|
|
59
|
+
event instanceof h3.H3Event || (event as any).__is_event__ ? event : event[HTTPEventSymbol];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (h3Function as any)(...args);
|
|
63
|
+
}) as any;
|
|
71
64
|
}
|
|
72
65
|
|
|
73
66
|
// Creating wrappers for each utility and exporting them with their original names
|
|
74
67
|
// readRawBody => getWebRequest().text()/.arrayBuffer()
|
|
75
68
|
type WrappedReadBody = <T, TEventInput = InferEventInput<"body", H3Event, T>>(
|
|
76
|
-
|
|
69
|
+
...args: Tail<Parameters<typeof h3.readBody<T, H3Event, TEventInput>>>
|
|
77
70
|
) => ReturnType<typeof h3.readBody<T, h3.H3Event, TEventInput>>;
|
|
78
71
|
export const readBody = createWrapperFunction(h3.readBody) as PrependOverload<
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
typeof h3.readBody,
|
|
73
|
+
WrappedReadBody
|
|
81
74
|
>;
|
|
82
|
-
type WrappedGetQuery = <
|
|
83
|
-
|
|
84
|
-
TEventInput = Exclude<InferEventInput<"query", H3Event, T>, undefined>,
|
|
85
|
-
>(
|
|
86
|
-
...args: Tail<Parameters<typeof h3.getQuery<T, H3Event, TEventInput>>>
|
|
75
|
+
type WrappedGetQuery = <T, TEventInput = Exclude<InferEventInput<"query", H3Event, T>, undefined>>(
|
|
76
|
+
...args: Tail<Parameters<typeof h3.getQuery<T, H3Event, TEventInput>>>
|
|
87
77
|
) => ReturnType<typeof h3.getQuery<T, H3Event, TEventInput>>;
|
|
88
78
|
export const getQuery = createWrapperFunction(h3.getQuery) as PrependOverload<
|
|
89
|
-
|
|
90
|
-
|
|
79
|
+
typeof h3.getQuery,
|
|
80
|
+
WrappedGetQuery
|
|
91
81
|
>;
|
|
92
82
|
export const isMethod = createWrapperFunction(h3.isMethod);
|
|
93
83
|
export const isPreflightRequest = createWrapperFunction(h3.isPreflightRequest);
|
|
94
84
|
type WrappedGetValidatedQuery = <
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
T extends HTTPEvent,
|
|
86
|
+
TEventInput = InferEventInput<"query", H3Event, T>,
|
|
97
87
|
>(
|
|
98
|
-
|
|
99
|
-
Parameters<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>
|
|
100
|
-
>
|
|
88
|
+
...args: Tail<Parameters<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>>
|
|
101
89
|
) => ReturnType<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>;
|
|
102
|
-
export const getValidatedQuery = createWrapperFunction(
|
|
103
|
-
|
|
104
|
-
|
|
90
|
+
export const getValidatedQuery = createWrapperFunction(h3.getValidatedQuery) as PrependOverload<
|
|
91
|
+
typeof h3.getValidatedQuery,
|
|
92
|
+
WrappedGetValidatedQuery
|
|
93
|
+
>;
|
|
105
94
|
export const getRouterParams = createWrapperFunction(h3.getRouterParams);
|
|
106
95
|
export const getRouterParam = createWrapperFunction(h3.getRouterParam);
|
|
107
96
|
type WrappedGetValidatedRouterParams = <
|
|
108
|
-
|
|
109
|
-
|
|
97
|
+
T extends HTTPEvent,
|
|
98
|
+
TEventInput = InferEventInput<"routerParams", H3Event, T>,
|
|
110
99
|
>(
|
|
111
|
-
|
|
112
|
-
Parameters<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>
|
|
113
|
-
>
|
|
100
|
+
...args: Tail<Parameters<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>>
|
|
114
101
|
) => ReturnType<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>;
|
|
115
102
|
export const getValidatedRouterParams = createWrapperFunction(
|
|
116
|
-
|
|
117
|
-
) as PrependOverload<
|
|
118
|
-
typeof h3.getValidatedRouterParams,
|
|
119
|
-
WrappedGetValidatedRouterParams
|
|
120
|
-
>;
|
|
103
|
+
h3.getValidatedRouterParams,
|
|
104
|
+
) as PrependOverload<typeof h3.getValidatedRouterParams, WrappedGetValidatedRouterParams>;
|
|
121
105
|
export const assertMethod = createWrapperFunction(h3.assertMethod);
|
|
122
106
|
export const getRequestHeaders = createWrapperFunction(h3.getRequestHeaders);
|
|
123
107
|
export const getRequestHeader = createWrapperFunction(h3.getRequestHeader);
|
|
@@ -126,53 +110,46 @@ export const getRequestHost = createWrapperFunction(h3.getRequestHost);
|
|
|
126
110
|
export const getRequestProtocol = createWrapperFunction(h3.getRequestProtocol);
|
|
127
111
|
export const getRequestIP = createWrapperFunction(h3.getRequestIP);
|
|
128
112
|
export const setResponseStatus = (code?: number, text?: string) => {
|
|
129
|
-
|
|
113
|
+
const e = getEvent();
|
|
130
114
|
|
|
131
|
-
|
|
132
|
-
|
|
115
|
+
if (e.res.status !== undefined) e.res.status = code;
|
|
116
|
+
if (e.res.statusText !== undefined) e.res.statusText = text;
|
|
133
117
|
};
|
|
134
118
|
export const getResponseStatus = () => getEvent().res.status;
|
|
135
119
|
export const getResponseStatusText = () => getEvent().res.statusText;
|
|
136
|
-
export const getResponseHeaders = () =>
|
|
137
|
-
|
|
138
|
-
export const getResponseHeader = (name: string) =>
|
|
139
|
-
getEvent().res.headers.get(name);
|
|
120
|
+
export const getResponseHeaders = () => Object.fromEntries(getEvent().res.headers.entries());
|
|
121
|
+
export const getResponseHeader = (name: string) => getEvent().res.headers.get(name);
|
|
140
122
|
export const setResponseHeaders = (values: Record<string, string>) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
123
|
+
const headers = getEvent().res.headers;
|
|
124
|
+
for (const [name, value] of Object.entries(values)) {
|
|
125
|
+
headers.set(name, value);
|
|
126
|
+
}
|
|
145
127
|
};
|
|
146
128
|
export const setResponseHeader = (name: string, value: string | string[]) => {
|
|
147
|
-
|
|
129
|
+
const headers = getEvent().res.headers;
|
|
148
130
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
131
|
+
(Array.isArray(value) ? value : [value]).forEach(value => {
|
|
132
|
+
headers.set(name, value);
|
|
133
|
+
});
|
|
152
134
|
};
|
|
153
135
|
export const appendResponseHeaders = (values: Record<string, string>) => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
136
|
+
const headers = getEvent().res.headers;
|
|
137
|
+
for (const [name, value] of Object.entries(values)) {
|
|
138
|
+
headers.append(name, value);
|
|
139
|
+
}
|
|
158
140
|
};
|
|
159
|
-
export const appendResponseHeader = (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
) => {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
(Array.isArray(value) ? value : [value]).forEach((value) => {
|
|
166
|
-
headers.append(name, value);
|
|
167
|
-
});
|
|
141
|
+
export const appendResponseHeader = (name: string, value: string | string[]) => {
|
|
142
|
+
const headers = getEvent().res.headers;
|
|
143
|
+
|
|
144
|
+
(Array.isArray(value) ? value : [value]).forEach(value => {
|
|
145
|
+
headers.append(name, value);
|
|
146
|
+
});
|
|
168
147
|
};
|
|
169
148
|
export const defaultContentType = (type: string) =>
|
|
170
|
-
|
|
149
|
+
getEvent().res.headers.set("content-type", type);
|
|
171
150
|
export const proxyRequest = createWrapperFunction(h3.proxyRequest);
|
|
172
151
|
export const fetchWithEvent = createWrapperFunction(h3.fetchWithEvent);
|
|
173
|
-
export const getProxyRequestHeaders = createWrapperFunction(
|
|
174
|
-
h3.getProxyRequestHeaders,
|
|
175
|
-
);
|
|
152
|
+
export const getProxyRequestHeaders = createWrapperFunction(h3.getProxyRequestHeaders);
|
|
176
153
|
|
|
177
154
|
export const parseCookies = createWrapperFunction(h3.parseCookies);
|
|
178
155
|
export const getCookie = createWrapperFunction(h3.getCookie);
|
|
@@ -181,73 +158,59 @@ export const deleteCookie = createWrapperFunction(h3.deleteCookie);
|
|
|
181
158
|
// not exported :(
|
|
182
159
|
type SessionDataT = Record<string, any>;
|
|
183
160
|
type WrappedUseSession = <T extends SessionDataT>(
|
|
184
|
-
|
|
161
|
+
...args: Tail<Parameters<typeof h3.useSession<T>>>
|
|
185
162
|
) => ReturnType<typeof h3.useSession<T>>;
|
|
186
|
-
export const useSession: WrappedUseSession = createWrapperFunction(
|
|
187
|
-
h3.useSession,
|
|
188
|
-
);
|
|
163
|
+
export const useSession: WrappedUseSession = createWrapperFunction(h3.useSession);
|
|
189
164
|
type WrappedGetSession = <T extends SessionDataT>(
|
|
190
|
-
|
|
165
|
+
...args: Tail<Parameters<typeof h3.getSession<T>>>
|
|
191
166
|
) => ReturnType<typeof h3.getSession<T>>;
|
|
192
|
-
export const getSession: WrappedGetSession = createWrapperFunction(
|
|
193
|
-
h3.getSession,
|
|
194
|
-
);
|
|
167
|
+
export const getSession: WrappedGetSession = createWrapperFunction(h3.getSession);
|
|
195
168
|
type WrappedUpdateSession = <T extends SessionDataT>(
|
|
196
|
-
|
|
169
|
+
...args: Tail<Parameters<typeof h3.updateSession<T>>>
|
|
197
170
|
) => ReturnType<typeof h3.updateSession<T>>;
|
|
198
|
-
export const updateSession: WrappedUpdateSession = createWrapperFunction(
|
|
199
|
-
h3.updateSession,
|
|
200
|
-
);
|
|
171
|
+
export const updateSession: WrappedUpdateSession = createWrapperFunction(h3.updateSession);
|
|
201
172
|
type WrappedSealSession = <T extends SessionDataT>(
|
|
202
|
-
|
|
173
|
+
...args: Tail<Parameters<typeof h3.sealSession<T>>>
|
|
203
174
|
) => ReturnType<typeof h3.sealSession<T>>;
|
|
204
|
-
export const sealSession: WrappedSealSession = createWrapperFunction(
|
|
205
|
-
h3.sealSession,
|
|
206
|
-
);
|
|
175
|
+
export const sealSession: WrappedSealSession = createWrapperFunction(h3.sealSession);
|
|
207
176
|
export const unsealSession = createWrapperFunction(h3.unsealSession);
|
|
208
177
|
export const clearSession = createWrapperFunction(h3.clearSession);
|
|
209
178
|
export const handleCacheHeaders = createWrapperFunction(h3.handleCacheHeaders);
|
|
210
179
|
export const handleCors = createWrapperFunction(h3.handleCors);
|
|
211
180
|
export const appendCorsHeaders = createWrapperFunction(h3.appendCorsHeaders);
|
|
212
|
-
export const appendCorsPreflightHeaders = createWrapperFunction(
|
|
213
|
-
h3.appendCorsPreflightHeaders,
|
|
214
|
-
);
|
|
181
|
+
export const appendCorsPreflightHeaders = createWrapperFunction(h3.appendCorsPreflightHeaders);
|
|
215
182
|
export const appendHeader = appendResponseHeader;
|
|
216
183
|
export const appendHeaders = appendResponseHeaders;
|
|
217
184
|
export const setHeader = setResponseHeader;
|
|
218
185
|
export const setHeaders = setResponseHeaders;
|
|
219
186
|
export const getHeader = getRequestHeader;
|
|
220
187
|
export const getHeaders = getRequestHeaders;
|
|
221
|
-
export const getRequestFingerprint = createWrapperFunction(
|
|
222
|
-
h3.getRequestFingerprint,
|
|
223
|
-
);
|
|
188
|
+
export const getRequestFingerprint = createWrapperFunction(h3.getRequestFingerprint);
|
|
224
189
|
export const getRequestWebStream = () => getEvent().req.body;
|
|
225
190
|
export const readFormData = () => getEvent().req.formData();
|
|
226
191
|
type WrappedReadValidatedBody = <
|
|
227
|
-
|
|
228
|
-
|
|
192
|
+
T extends HTTPEvent,
|
|
193
|
+
TEventInput = InferEventInput<"body", H3Event, T>,
|
|
229
194
|
>(
|
|
230
|
-
|
|
231
|
-
Parameters<typeof h3.readValidatedBody<T, H3Event, TEventInput>>
|
|
232
|
-
>
|
|
195
|
+
...args: Tail<Parameters<typeof h3.readValidatedBody<T, H3Event, TEventInput>>>
|
|
233
196
|
) => ReturnType<typeof h3.readValidatedBody<T, H3Event, TEventInput>>;
|
|
234
|
-
export const readValidatedBody = createWrapperFunction(
|
|
235
|
-
|
|
236
|
-
|
|
197
|
+
export const readValidatedBody = createWrapperFunction(h3.readValidatedBody) as PrependOverload<
|
|
198
|
+
typeof h3.readValidatedBody,
|
|
199
|
+
WrappedReadValidatedBody
|
|
200
|
+
>;
|
|
237
201
|
export const getContext = createWrapperFunction(_getContext);
|
|
238
202
|
export const setContext = createWrapperFunction(_setContext);
|
|
239
|
-
export const removeResponseHeader = (name: string) =>
|
|
240
|
-
getEvent().res.headers.delete(name);
|
|
203
|
+
export const removeResponseHeader = (name: string) => getEvent().res.headers.delete(name);
|
|
241
204
|
export const clearResponseHeaders = (headerNames?: string[]) => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
205
|
+
const headers = getEvent().res.headers;
|
|
206
|
+
|
|
207
|
+
if (headerNames && headerNames.length > 0) {
|
|
208
|
+
for (const name of headerNames) {
|
|
209
|
+
headers.delete(name);
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
for (const name of headers.keys()) {
|
|
213
|
+
headers.delete(name);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
253
216
|
};
|
package/src/index.tsx
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
// @refresh skip
|
|
2
2
|
|
|
3
|
-
export type {
|
|
4
|
-
APIEvent,
|
|
5
|
-
APIHandler,
|
|
6
|
-
Asset,
|
|
7
|
-
ContextMatches,
|
|
8
|
-
DocumentComponentProps,
|
|
9
|
-
FetchEvent,
|
|
10
|
-
HandlerOptions,
|
|
11
|
-
PageEvent,
|
|
12
|
-
ResponseStub,
|
|
13
|
-
ServerFunctionMeta
|
|
14
|
-
} from "./server/types.ts";
|
|
15
3
|
export { default as clientOnly } from "./shared/clientOnly.ts";
|
|
16
4
|
export { GET } from "./shared/GET.ts";
|
|
17
5
|
export { HttpHeader } from "./shared/HttpHeader.tsx";
|
package/src/internal.d.ts
CHANGED
package/src/middleware/index.ts
CHANGED
|
@@ -10,73 +10,63 @@ export type MiddlewareFn = (event: FetchEvent) => Promise<unknown> | unknown;
|
|
|
10
10
|
/** This composes an array of Exchanges into a single ExchangeIO function */
|
|
11
11
|
|
|
12
12
|
export type RequestMiddleware = (
|
|
13
|
-
|
|
14
|
-
) =>
|
|
15
|
-
| Response
|
|
16
|
-
| Promise<Response>
|
|
17
|
-
| void
|
|
18
|
-
| Promise<void>
|
|
19
|
-
| Promise<void | Response>;
|
|
13
|
+
event: FetchEvent,
|
|
14
|
+
) => Response | Promise<Response> | void | Promise<void> | Promise<void | Response>;
|
|
20
15
|
|
|
21
16
|
// copy-pasted from h3/dist/index.d.ts
|
|
22
17
|
type EventHandlerResponse<T = any> = T | Promise<T>;
|
|
23
18
|
type ResponseMiddlewareResponseParam = { body?: Awaited<EventHandlerResponse> };
|
|
24
19
|
|
|
25
20
|
export type ResponseMiddleware = (
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
event: FetchEvent,
|
|
22
|
+
response: ResponseMiddlewareResponseParam,
|
|
28
23
|
) => Response | Promise<Response> | void | Promise<void>;
|
|
29
24
|
|
|
30
25
|
function wrapRequestMiddleware(onRequest: RequestMiddleware) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
return async (h3Event: H3Event) => {
|
|
27
|
+
const fetchEvent = getFetchEvent(h3Event);
|
|
28
|
+
const response = await onRequest(fetchEvent);
|
|
29
|
+
if (response) return response;
|
|
30
|
+
};
|
|
36
31
|
}
|
|
37
32
|
|
|
38
|
-
function wrapResponseMiddleware(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return async (h3Event, next) => {
|
|
42
|
-
const resp = await next();
|
|
33
|
+
function wrapResponseMiddleware(onBeforeResponse: ResponseMiddleware): Middleware {
|
|
34
|
+
return async (h3Event, next) => {
|
|
35
|
+
const resp = await next();
|
|
43
36
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
const fetchEvent = getFetchEvent(h3Event);
|
|
38
|
+
const mwResponse = await onBeforeResponse(fetchEvent, {
|
|
39
|
+
body: (resp as any)?.body,
|
|
40
|
+
});
|
|
41
|
+
if (mwResponse) return mwResponse;
|
|
42
|
+
};
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
export function createMiddleware(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
| undefined;
|
|
62
|
-
}
|
|
63
|
-
| Middleware[],
|
|
46
|
+
args:
|
|
47
|
+
| {
|
|
48
|
+
/** @deprecated Use H3 `Middleware` */
|
|
49
|
+
onRequest?: RequestMiddleware | RequestMiddleware[] | undefined;
|
|
50
|
+
/** @deprecated Use H3 `Middleware` */
|
|
51
|
+
onBeforeResponse?: ResponseMiddleware | ResponseMiddleware[] | undefined;
|
|
52
|
+
}
|
|
53
|
+
| Middleware[],
|
|
64
54
|
): Middleware[] {
|
|
65
|
-
|
|
55
|
+
if (Array.isArray(args)) return args;
|
|
66
56
|
|
|
67
|
-
|
|
57
|
+
const mw: Middleware[] = [];
|
|
68
58
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
if (typeof args.onRequest === "function") {
|
|
60
|
+
mw.push(wrapRequestMiddleware(args.onRequest));
|
|
61
|
+
} else if (Array.isArray(args.onRequest)) {
|
|
62
|
+
mw.push(...args.onRequest.map(wrapRequestMiddleware));
|
|
63
|
+
}
|
|
74
64
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
if (typeof args.onBeforeResponse === "function") {
|
|
66
|
+
mw.push(wrapResponseMiddleware(args.onBeforeResponse));
|
|
67
|
+
} else if (Array.isArray(args.onBeforeResponse)) {
|
|
68
|
+
mw.push(...args.onBeforeResponse.map(wrapResponseMiddleware));
|
|
69
|
+
}
|
|
80
70
|
|
|
81
|
-
|
|
71
|
+
return mw;
|
|
82
72
|
}
|
package/src/router.tsx
CHANGED
|
@@ -8,17 +8,18 @@ const components: Record<string, Component> = {};
|
|
|
8
8
|
|
|
9
9
|
export function createRoutes() {
|
|
10
10
|
function createRoute(route: any) {
|
|
11
|
-
const component =
|
|
11
|
+
const component =
|
|
12
|
+
route.$component && (components[route.$component.src] ??= lazy(route.$component.import));
|
|
12
13
|
|
|
13
14
|
return {
|
|
14
15
|
...route,
|
|
15
16
|
...(route.$$route ? route.$$route.require().route : undefined),
|
|
16
17
|
info: {
|
|
17
18
|
...(route.$$route ? route.$$route.require().route.info : {}),
|
|
18
|
-
filesystem: true
|
|
19
|
+
filesystem: true,
|
|
19
20
|
},
|
|
20
21
|
component,
|
|
21
|
-
children: route.children ? route.children.map(createRoute) : undefined
|
|
22
|
+
children: route.children ? route.children.map(createRoute) : undefined,
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
const routes = routeConfigs.map(createRoute);
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
// @refresh skip
|
|
2
2
|
import type { Component } from "solid-js";
|
|
3
|
-
import {
|
|
4
|
-
Hydration,
|
|
5
|
-
HydrationScript,
|
|
6
|
-
NoHydration,
|
|
7
|
-
getRequestEvent,
|
|
8
|
-
ssr
|
|
9
|
-
} from "solid-js/web";
|
|
3
|
+
import { Hydration, HydrationScript, NoHydration, getRequestEvent, ssr } from "solid-js/web";
|
|
10
4
|
import App from "solid-start:app";
|
|
11
5
|
|
|
12
6
|
import { ErrorBoundary, TopErrorBoundary } from "../shared/ErrorBoundary.tsx";
|
|
@@ -18,11 +18,15 @@ const assetMap = {
|
|
|
18
18
|
},
|
|
19
19
|
noscript: (props: { attrs: JSX.HTMLAttributes<HTMLElement>; children: JSX.Element }) => (
|
|
20
20
|
<noscript {...props.attrs}>{props.children}</noscript>
|
|
21
|
-
)
|
|
21
|
+
),
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export function renderAsset(asset: Asset, nonce?: string) {
|
|
25
|
-
let {
|
|
25
|
+
let {
|
|
26
|
+
tag,
|
|
27
|
+
attrs: { key, ...attrs } = { key: undefined },
|
|
28
|
+
children,
|
|
29
|
+
} = asset as any;
|
|
26
30
|
return (assetMap as any)[tag]({ attrs: { ...attrs, nonce }, key, children });
|
|
27
31
|
}
|
|
28
32
|
|