aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-21 01:09:37 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-21 01:09:37 -0700
commita1f40400c158316b1e57ec9bc53887efdb645192 (patch)
tree3721de20291190bde780e88edbe0637447def036 /examples
parentc940f00e2d49ea37ac69589a9a160a43df91eeb6 (diff)
downloadbun-a1f40400c158316b1e57ec9bc53887efdb645192.tar.gz
bun-a1f40400c158316b1e57ec9bc53887efdb645192.tar.zst
bun-a1f40400c158316b1e57ec9bc53887efdb645192.zip
Fix "/" in example
Diffstat (limited to 'examples')
-rw-r--r--examples/http-file.ts13
1 files changed, 10 insertions, 3 deletions
diff --git a/examples/http-file.ts b/examples/http-file.ts
index 2789f09a1..130104534 100644
--- a/examples/http-file.ts
+++ b/examples/http-file.ts
@@ -1,8 +1,15 @@
-const { serve, file, resolveSync } = Bun;
-const { path } = import.meta;
+import { file } from "bun";
+
serve({
fetch(req: Request) {
- return new Response(file(new URL(req.url).pathname.substring(1)));
+ const pathname = new URL(req.url).pathname.substring(1);
+
+ // If the URL is empty, display this file.
+ if (pathname === "") {
+ return new Response(file(import.meta.url));
+ }
+
+ return new Response(file(pathname));
},
// this is called when fetch() throws or rejects