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.
@@ -16,7 +16,9 @@ type ServeResponse = {
16
16
  body: Uint8Array | string;
17
17
  headers?: Record<string, string>;
18
18
  };
19
- type ServeFallback = () => ServeResponse | Promise<ServeResponse>;
19
+ type ServeFallback = (req: {
20
+ href: string;
21
+ }) => ServeResponse | Promise<ServeResponse>;
20
22
  type ServeConfig = {
21
23
  dir: string;
22
24
  fallback?: string | ServeFallback;
@@ -150,14 +150,23 @@ export class Yedra {
150
150
  };
151
151
  }
152
152
  if (serveData.fallback !== undefined) {
153
- const response = await serveData.fallback();
154
- return {
155
- status: response.status ?? 200,
156
- body: isUint8Array(response.body)
157
- ? response.body
158
- : Buffer.from(response.body, 'utf-8'),
159
- headers: response.headers,
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yedra",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "repository": "github:0codekit/yedra",
5
5
  "main": "dist/index.js",
6
6
  "devDependencies": {