aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-07 06:26:28 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-07 06:26:28 -0700
commit69cebbfca2046140c97a4c36bc9f105fe51c9c2f (patch)
tree78da5640c76699153cec8e19a35e8ba661672b8f
parent3c4510573edd7a110c3add65c48cd5ef8c103045 (diff)
downloadbun-69cebbfca2046140c97a4c36bc9f105fe51c9c2f.tar.gz
bun-69cebbfca2046140c97a4c36bc9f105fe51c9c2f.tar.zst
bun-69cebbfca2046140c97a4c36bc9f105fe51c9c2f.zip
Update http-file.ts
-rw-r--r--examples/http-file.ts15
1 files changed, 8 insertions, 7 deletions
diff --git a/examples/http-file.ts b/examples/http-file.ts
index 242aacd95..4eaa03212 100644
--- a/examples/http-file.ts
+++ b/examples/http-file.ts
@@ -1,11 +1,12 @@
const { serve, file, resolveSync } = Bun;
-const { url: baseURL, path: basePath } = import.meta;
-
-// Start a fast HTTP server from a function
+const { path } = import.meta;
serve({
- fetch({ url }: Request) {
- const { pathname } = new URL(url.slice(1), baseURL);
- return new Response(file(resolveSync(pathname, basePath)));
+ fetch(req: Request) {
+ const modulePath = resolveSync(
+ new URL(req.url).pathname.substring(1),
+ path
+ );
+ return new Response(file(modulePath));
},
// this is called when fetch() throws or rejects
@@ -22,6 +23,6 @@ serve({
// certFile: './cert.pem',
// keyFile: './key.pem',
- port: 8080, // number or string
+ port: 3000, // number or string
hostname: "localhost", // defaults to 0.0.0.0
});