yedra 0.15.0 → 0.15.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/dist/routing/app.d.ts +3 -1
- package/dist/routing/app.js +17 -8
- package/package.json +1 -1
package/dist/routing/app.d.ts
CHANGED
|
@@ -16,7 +16,9 @@ type ServeResponse = {
|
|
|
16
16
|
body: Uint8Array | string;
|
|
17
17
|
headers?: Record<string, string>;
|
|
18
18
|
};
|
|
19
|
-
type ServeFallback = (
|
|
19
|
+
type ServeFallback = (req: {
|
|
20
|
+
href: string;
|
|
21
|
+
}) => ServeResponse | Promise<ServeResponse>;
|
|
20
22
|
type ServeConfig = {
|
|
21
23
|
dir: string;
|
|
22
24
|
fallback?: string | ServeFallback;
|
package/dist/routing/app.js
CHANGED
|
@@ -150,14 +150,23 @@ export class Yedra {
|
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
if (serveData.fallback !== undefined) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
153
|
+
try {
|
|
154
|
+
const response = await serveData.fallback({ href: req.url.href });
|
|
155
|
+
return {
|
|
156
|
+
status: response.status ?? 200,
|
|
157
|
+
body: isUint8Array(response.body)
|
|
158
|
+
? response.body
|
|
159
|
+
: Buffer.from(response.body, 'utf-8'),
|
|
160
|
+
headers: response.headers,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
if (error instanceof HttpError) {
|
|
165
|
+
return Yedra.errorResponse(error.status, error.message);
|
|
166
|
+
}
|
|
167
|
+
console.error(error);
|
|
168
|
+
return Yedra.errorResponse(500, 'Internal Server Error.');
|
|
169
|
+
}
|
|
161
170
|
}
|
|
162
171
|
}
|
|
163
172
|
if (match.invalidMethod) {
|