From 81eb47de0eb08081ed0677b71aa47e9a2b473cab Mon Sep 17 00:00:00 2001 From: Jarred SUmner Date: Wed, 6 Apr 2022 01:52:15 -0700 Subject: [bun.js] Add stdout, stderr, stdin to Bun and support sendfile() + splice() --- examples/http-file.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/http-file.ts (limited to 'examples/http-file.ts') diff --git a/examples/http-file.ts b/examples/http-file.ts new file mode 100644 index 000000000..f2c0773e8 --- /dev/null +++ b/examples/http-file.ts @@ -0,0 +1,25 @@ +// Start a fast HTTP server from a function +Bun.serve({ + fetch(req) { + const url = new URL(req.url.substring(1), "file://" + import.meta.path); + const path = Bun.resolveSync(url.pathname, import.meta.path); + return new Response(Bun.file(path)); + }, + + // this is called when fetch() throws or rejects + // error(err: Error) { + // return new Response("uh oh! :(" + String(err.toString()), { status: 500 }); + // }, + + // this boolean enables the bun's default error handler + // sometime after the initial release, it will auto reload as well + development: process.env.NODE_ENV !== "production", + // note: this isn't node, but for compatibility bun supports process.env + more stuff in process + + // SSL is enabled if these two are set + // certFile: './cert.pem', + // keyFile: './key.pem', + + port: 8080, // number or string + hostname: "localhost", // defaults to 0.0.0.0 +}); -- cgit v1.2.3