diff options
author | 2021-12-22 21:35:08 -0800 | |
---|---|---|
committer | 2021-12-22 21:35:08 -0800 | |
commit | 8e05fbf43fe75d8c01cbcf2c4fc79d4af2b25346 (patch) | |
tree | 2f57325869429057db7854c8875f242acd03706d /packages/bun-framework-next/server.development.tsx | |
parent | c59ff7416abeb52ecd2eb8328f4313e1f3b0b722 (diff) | |
download | bun-8e05fbf43fe75d8c01cbcf2c4fc79d4af2b25346.tar.gz bun-8e05fbf43fe75d8c01cbcf2c4fc79d4af2b25346.tar.zst bun-8e05fbf43fe75d8c01cbcf2c4fc79d4af2b25346.zip |
Fix URL() in bun-framework-next
Diffstat (limited to 'packages/bun-framework-next/server.development.tsx')
-rw-r--r-- | packages/bun-framework-next/server.development.tsx | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/packages/bun-framework-next/server.development.tsx b/packages/bun-framework-next/server.development.tsx index 4ac2621e8..3689dc96e 100644 --- a/packages/bun-framework-next/server.development.tsx +++ b/packages/bun-framework-next/server.development.tsx @@ -17,8 +17,8 @@ if ( let buildId = 0; -var DocumentLoaded = false; -var DocumentNamespace; +let DocumentLoaded = false; +let DocumentNamespace; import(Bun.routesDir + "_document").then( (doc) => { @@ -37,25 +37,39 @@ import(Bun.routesDir + "_document").then( ); addEventListener("fetch", async (event: FetchEvent) => { - var route = Bun.match(event); + const route = Bun.match(event); // This imports the currently matched route. - const PageNamespace = await import(route.filePath); + let PageNamespace: any; + + try { + PageNamespace = await import(route.filePath); + } catch (exception) { + console.error("Error loading page:", route.filePath); + throw exception; + } // This returns all .css files that were imported in the line above. // It's recursive, so any file that imports a CSS file will be included. const pageStylesheets = (Bun.getImportedStyles() as string[]).slice(); - var appRoute; + let appRoute: any; try { appRoute = await import(Bun.routesDir + "_app"); } catch (exception) { - appRoute = null; + // ResolveError is defined outside of bun-framework-next in ../../src/runtime/errors + // @ts-expect-error + if (exception && !(exception instanceof ResolveError)) { + console.error("Error loading app:", Bun.routesDir + "_app"); + throw exception; + } } + const appStylesheets = (Bun.getImportedStyles() as string[]).slice(); - event.respondWith( - render({ + let response: Response; + try { + response = await render({ route, PageNamespace, appStylesheets, @@ -66,12 +80,16 @@ addEventListener("fetch", async (event: FetchEvent) => { routePaths: Bun.getRouteFiles(), routeNames: Bun.getRouteNames(), request: event.request, - }) - ); + }); + } catch (exception) { + console.error("Error rendering route", route.filePath); + throw exception; + } + + event.respondWith(response); + buildId++; }); -// typescript isolated modules +declare let Bun: any; export {}; - -declare var Bun: any; |