diff options
author | 2021-08-17 01:44:30 -0700 | |
---|---|---|
committer | 2021-08-17 01:44:30 -0700 | |
commit | 574be79253f503fe3caedf5d66b1ff35f71a55d0 (patch) | |
tree | 1b55bb45d754a33428267834b75bd26ee1fa21fb /demos/css-stress-test/bun-framework-next/server.development.tsx | |
parent | 209391d01c9fad548d5b84d8d0c530d317aa1d92 (diff) | |
download | bun-574be79253f503fe3caedf5d66b1ff35f71a55d0.tar.gz bun-574be79253f503fe3caedf5d66b1ff35f71a55d0.tar.zst bun-574be79253f503fe3caedf5d66b1ff35f71a55d0.zip |
alright thats the rename
Former-commit-id: 0faf61249e76382dfb1aa8721249474eae920753
Diffstat (limited to 'demos/css-stress-test/bun-framework-next/server.development.tsx')
-rw-r--r-- | demos/css-stress-test/bun-framework-next/server.development.tsx | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/demos/css-stress-test/bun-framework-next/server.development.tsx b/demos/css-stress-test/bun-framework-next/server.development.tsx new file mode 100644 index 000000000..1f0eaee50 --- /dev/null +++ b/demos/css-stress-test/bun-framework-next/server.development.tsx @@ -0,0 +1,67 @@ +import { render } from "./renderDocument"; + +let buildId = 0; + +var DocumentNamespacePromise; + +DocumentNamespacePromise = import(Bun.routesDir + "_document"); +var DocumentLoaded = false; +var DocumentNamespace; + +addEventListener("fetch", async (event: FetchEvent) => { + if (!DocumentLoaded) { + DocumentLoaded = true; + try { + DocumentNamespace = await DocumentNamespacePromise; + } catch (exception) { + DocumentNamespace = null; + } + } + + var appRoute; + + try { + appRoute = await import(Bun.routesDir + "_app"); + } catch (exception) { + appRoute = null; + } + const appStylesheets = (Bun.getImportedStyles() as string[]).slice(); + var route = Bun.match(event); + + // This imports the currently matched route. + const PageNamespace = await import(route.filePath); + + // 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(); + + event.respondWith( + render({ + route, + PageNamespace, + appStylesheets, + pageStylesheets, + DocumentNamespace, + AppNamespace: appRoute, + buildId, + routePaths: Bun.getRouteFiles(), + }) + ); + buildId++; +}); + +// typescript isolated modules +export {}; + +declare var Bun: any; + +function getNextData(request: Request, route) { + return { + NEXT_DATA: { + query: route.query, + props: {}, + page: route.path, + buildId: buildId.toString(16), + }, + }; +} |