@richie-router/server 0.1.1 → 0.1.2
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/dist/cjs/index.cjs +38 -23
- package/dist/esm/index.mjs +38 -23
- package/dist/types/index.d.ts +5 -0
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ var __export = (target, all) => {
|
|
|
40
40
|
var exports_src = {};
|
|
41
41
|
__export(exports_src, {
|
|
42
42
|
handleRequest: () => handleRequest,
|
|
43
|
+
handleHeadTagRequest: () => handleHeadTagRequest,
|
|
43
44
|
defineHeadTags: () => defineHeadTags
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(exports_src);
|
|
@@ -140,35 +141,49 @@ async function resolveMatchedHead(request, headTags, matches) {
|
|
|
140
141
|
}
|
|
141
142
|
return import_core.resolveHeadConfig(matches, resolvedHeadByRoute);
|
|
142
143
|
}
|
|
143
|
-
async function
|
|
144
|
+
async function handleHeadTagRequest(request, options) {
|
|
144
145
|
const url = new URL(request.url);
|
|
145
146
|
const headBasePath = options.headBasePath ?? "/head-api";
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
147
|
+
if (!url.pathname.startsWith(`${headBasePath}/`)) {
|
|
148
|
+
return {
|
|
149
|
+
matched: false,
|
|
150
|
+
response: new Response("Not Found", { status: 404 })
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const headTagName = decodeURIComponent(url.pathname.slice(headBasePath.length + 1));
|
|
154
|
+
const params = JSON.parse(url.searchParams.get("params") ?? "{}");
|
|
155
|
+
const search = JSON.parse(url.searchParams.get("search") ?? "{}");
|
|
156
|
+
try {
|
|
157
|
+
const result = await executeHeadTag(request, options.headTags, headTagName, params, search);
|
|
158
|
+
return {
|
|
159
|
+
matched: true,
|
|
160
|
+
response: jsonResponse(result)
|
|
161
|
+
};
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (error instanceof Response) {
|
|
153
164
|
return {
|
|
154
165
|
matched: true,
|
|
155
|
-
response:
|
|
166
|
+
response: error
|
|
156
167
|
};
|
|
157
|
-
} catch (error) {
|
|
158
|
-
if (error instanceof Response) {
|
|
159
|
-
return {
|
|
160
|
-
matched: true,
|
|
161
|
-
response: error
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
if (import_core.isNotFound(error)) {
|
|
165
|
-
return {
|
|
166
|
-
matched: true,
|
|
167
|
-
response: jsonResponse({ message: "Not Found" }, { status: 404 })
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
throw error;
|
|
171
168
|
}
|
|
169
|
+
if (import_core.isNotFound(error)) {
|
|
170
|
+
return {
|
|
171
|
+
matched: true,
|
|
172
|
+
response: jsonResponse({ message: "Not Found" }, { status: 404 })
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async function handleRequest(request, options) {
|
|
179
|
+
const url = new URL(request.url);
|
|
180
|
+
const routeBasePath = options.routeBasePath ?? "/";
|
|
181
|
+
const handledHeadTagRequest = await handleHeadTagRequest(request, {
|
|
182
|
+
headTags: options.headTags,
|
|
183
|
+
headBasePath: options.headBasePath
|
|
184
|
+
});
|
|
185
|
+
if (handledHeadTagRequest.matched) {
|
|
186
|
+
return handledHeadTagRequest;
|
|
172
187
|
}
|
|
173
188
|
if (!url.pathname.startsWith(routeBasePath)) {
|
|
174
189
|
return {
|
package/dist/esm/index.mjs
CHANGED
|
@@ -106,35 +106,49 @@ async function resolveMatchedHead(request, headTags, matches) {
|
|
|
106
106
|
}
|
|
107
107
|
return resolveHeadConfig(matches, resolvedHeadByRoute);
|
|
108
108
|
}
|
|
109
|
-
async function
|
|
109
|
+
async function handleHeadTagRequest(request, options) {
|
|
110
110
|
const url = new URL(request.url);
|
|
111
111
|
const headBasePath = options.headBasePath ?? "/head-api";
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
if (!url.pathname.startsWith(`${headBasePath}/`)) {
|
|
113
|
+
return {
|
|
114
|
+
matched: false,
|
|
115
|
+
response: new Response("Not Found", { status: 404 })
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const headTagName = decodeURIComponent(url.pathname.slice(headBasePath.length + 1));
|
|
119
|
+
const params = JSON.parse(url.searchParams.get("params") ?? "{}");
|
|
120
|
+
const search = JSON.parse(url.searchParams.get("search") ?? "{}");
|
|
121
|
+
try {
|
|
122
|
+
const result = await executeHeadTag(request, options.headTags, headTagName, params, search);
|
|
123
|
+
return {
|
|
124
|
+
matched: true,
|
|
125
|
+
response: jsonResponse(result)
|
|
126
|
+
};
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (error instanceof Response) {
|
|
119
129
|
return {
|
|
120
130
|
matched: true,
|
|
121
|
-
response:
|
|
131
|
+
response: error
|
|
122
132
|
};
|
|
123
|
-
} catch (error) {
|
|
124
|
-
if (error instanceof Response) {
|
|
125
|
-
return {
|
|
126
|
-
matched: true,
|
|
127
|
-
response: error
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
if (isNotFound(error)) {
|
|
131
|
-
return {
|
|
132
|
-
matched: true,
|
|
133
|
-
response: jsonResponse({ message: "Not Found" }, { status: 404 })
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
throw error;
|
|
137
133
|
}
|
|
134
|
+
if (isNotFound(error)) {
|
|
135
|
+
return {
|
|
136
|
+
matched: true,
|
|
137
|
+
response: jsonResponse({ message: "Not Found" }, { status: 404 })
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async function handleRequest(request, options) {
|
|
144
|
+
const url = new URL(request.url);
|
|
145
|
+
const routeBasePath = options.routeBasePath ?? "/";
|
|
146
|
+
const handledHeadTagRequest = await handleHeadTagRequest(request, {
|
|
147
|
+
headTags: options.headTags,
|
|
148
|
+
headBasePath: options.headBasePath
|
|
149
|
+
});
|
|
150
|
+
if (handledHeadTagRequest.matched) {
|
|
151
|
+
return handledHeadTagRequest;
|
|
138
152
|
}
|
|
139
153
|
if (!url.pathname.startsWith(routeBasePath)) {
|
|
140
154
|
return {
|
|
@@ -203,5 +217,6 @@ async function handleRequest(request, options) {
|
|
|
203
217
|
}
|
|
204
218
|
export {
|
|
205
219
|
handleRequest,
|
|
220
|
+
handleHeadTagRequest,
|
|
206
221
|
defineHeadTags
|
|
207
222
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -32,8 +32,13 @@ export interface HandleRequestOptions<TRouteManifest extends AnyRoute, THeadTagS
|
|
|
32
32
|
headBasePath?: string;
|
|
33
33
|
routeBasePath?: string;
|
|
34
34
|
}
|
|
35
|
+
export interface HandleHeadTagRequestOptions<TRouteManifest extends AnyRoute, THeadTagSchema extends HeadTagSchemaShape, TDefinitions extends Partial<Record<keyof THeadTagSchema, HeadTagDefinition<any>>>> {
|
|
36
|
+
headTags: DefinedHeadTags<TRouteManifest, THeadTagSchema, TDefinitions>;
|
|
37
|
+
headBasePath?: string;
|
|
38
|
+
}
|
|
35
39
|
export interface HandleRequestResult {
|
|
36
40
|
matched: boolean;
|
|
37
41
|
response: Response;
|
|
38
42
|
}
|
|
43
|
+
export declare function handleHeadTagRequest<TRouteManifest extends AnyRoute, THeadTagSchema extends HeadTagSchemaShape, TDefinitions extends Partial<Record<keyof THeadTagSchema, HeadTagDefinition<any>>>>(request: Request, options: HandleHeadTagRequestOptions<TRouteManifest, THeadTagSchema, TDefinitions>): Promise<HandleRequestResult>;
|
|
39
44
|
export declare function handleRequest<TRouteManifest extends AnyRoute, THeadTagSchema extends HeadTagSchemaShape, TDefinitions extends Partial<Record<keyof THeadTagSchema, HeadTagDefinition<any>>>>(request: Request, options: HandleRequestOptions<TRouteManifest, THeadTagSchema, TDefinitions>): Promise<HandleRequestResult>;
|