diff options
author | 2022-04-07 06:08:48 -0700 | |
---|---|---|
committer | 2022-04-07 06:08:48 -0700 | |
commit | b97e81b27faf3d8805a8670035298d910cd32a83 (patch) | |
tree | 361f2a70077a5bc4a328cbaa48ff38b63f821c6b /examples/http-file.ts | |
parent | e08cc968cb531e35aa93e45c3443bc8d16854b83 (diff) | |
download | bun-b97e81b27faf3d8805a8670035298d910cd32a83.tar.gz bun-b97e81b27faf3d8805a8670035298d910cd32a83.tar.zst bun-b97e81b27faf3d8805a8670035298d910cd32a83.zip |
More types
Diffstat (limited to 'examples/http-file.ts')
-rw-r--r-- | examples/http-file.ts | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/examples/http-file.ts b/examples/http-file.ts index 3c1d67169..242aacd95 100644 --- a/examples/http-file.ts +++ b/examples/http-file.ts @@ -1,7 +1,11 @@ +const { serve, file, resolveSync } = Bun; +const { url: baseURL, path: basePath } = import.meta; + // Start a fast HTTP server from a function -Bun.serve({ - fetch(req) { - return new Response("Hello World!"); +serve({ + fetch({ url }: Request) { + const { pathname } = new URL(url.slice(1), baseURL); + return new Response(file(resolveSync(pathname, basePath))); }, // this is called when fetch() throws or rejects |