diff options
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 |