diff options
author | 2022-04-06 01:52:15 -0700 | |
---|---|---|
committer | 2022-04-06 01:53:05 -0700 | |
commit | 81eb47de0eb08081ed0677b71aa47e9a2b473cab (patch) | |
tree | 051df34c66832ab2f0986370d5c8fbb3e12058fc /examples/http.ts | |
parent | 57cf035a73187439fbcd8703d7f4358463ee8314 (diff) | |
download | bun-81eb47de0eb08081ed0677b71aa47e9a2b473cab.tar.gz bun-81eb47de0eb08081ed0677b71aa47e9a2b473cab.tar.zst bun-81eb47de0eb08081ed0677b71aa47e9a2b473cab.zip |
[bun.js] Add stdout, stderr, stdin to Bun and support sendfile() + splice()
Diffstat (limited to 'examples/http.ts')
-rw-r--r-- | examples/http.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/http.ts b/examples/http.ts new file mode 100644 index 000000000..4d58f270f --- /dev/null +++ b/examples/http.ts @@ -0,0 +1,35 @@ +// Start a fast HTTP server from a function +Bun.serve({ + fetch(req) { + return new Response("Hello World!"); + }, + + // this is called when fetch() throws or rejects + error(err: Error) { + return new Response("uh oh! :(" + 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 +}); + +// Start a fast HTTP server from the main file's export +// export default { +// fetch(req) { +// return new Response( +// `This is another way to start a server! +// if the main file export default's an object +// with 'fetch'. Bun automatically calls Bun.serve` +// ); +// }, +// // so autocomplete & type checking works +// } as Bun.Serve; |