aboutsummaryrefslogtreecommitdiff
path: root/examples/hello-next/bun-framework-next/server.development.tsx
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-07 22:08:18 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-07 22:08:18 -0700
commit2a6edf00cdb1326267d9099adc2986c94f048134 (patch)
tree827830dd77e1feb5fe5b292b2a1f755442bdd400 /examples/hello-next/bun-framework-next/server.development.tsx
parentcbd2c56a1fb0fd36f34af20a38e681d6e5e9d64b (diff)
downloadbun-2a6edf00cdb1326267d9099adc2986c94f048134.tar.gz
bun-2a6edf00cdb1326267d9099adc2986c94f048134.tar.zst
bun-2a6edf00cdb1326267d9099adc2986c94f048134.zip
lotta changes
Diffstat (limited to 'examples/hello-next/bun-framework-next/server.development.tsx')
-rw-r--r--examples/hello-next/bun-framework-next/server.development.tsx79
1 files changed, 79 insertions, 0 deletions
diff --git a/examples/hello-next/bun-framework-next/server.development.tsx b/examples/hello-next/bun-framework-next/server.development.tsx
new file mode 100644
index 000000000..e3cd24e01
--- /dev/null
+++ b/examples/hello-next/bun-framework-next/server.development.tsx
@@ -0,0 +1,79 @@
+import * as React from "react";
+import { Buffer } from "buffer";
+globalThis.Buffer = Buffer;
+
+class URL {
+ constructor(base, source) {
+ this.pathname = source;
+ this.href = base + source;
+ }
+}
+var onlyChildPolyfill = React.Children.only;
+React.Children.only = function (children) {
+ if (children && typeof children === "object" && children.length == 1) {
+ return onlyChildPolyfill(children[0]);
+ }
+
+ return onlyChildPolyfill(children);
+};
+globalThis.URL = URL;
+globalThis.global = globalThis;
+import { render } from "./renderDocument";
+
+let buildId = 0;
+
+var DocumentLoaded = false;
+var DocumentNamespace;
+
+import(Bun.routesDir + "_document").then(
+ (doc) => {
+ DocumentNamespace = doc;
+ DocumentLoaded = true;
+ },
+ (err) => {
+ if (err instanceof ResolveError) {
+ DocumentLoaded = true;
+ } else {
+ console.error(err);
+ }
+ }
+);
+
+addEventListener("fetch", async (event: FetchEvent) => {
+ 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();
+
+ var appRoute;
+
+ try {
+ appRoute = await import(Bun.routesDir + "_app");
+ } catch (exception) {
+ appRoute = null;
+ }
+ const appStylesheets = (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;