mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
* Add bun-types to packages * Improve typing * Fix types in tests * Fix dts tests * Run formatter * Fix all type errors * Add strict mode, fix type errors * Add ffi changes * Move workflows to root * Add workflows * Remove labeler * Add child_process types * Fix synthetic defaults issue * Remove docs * Move scripts * Run prettier * Include examples in typechecking * captureStackTrace types * moved captureStackTrace types to globals * Address reviews Co-authored-by: Colin McDonnell <colinmcd@alum.mit.edu> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
32 lines
939 B
TypeScript
32 lines
939 B
TypeScript
import { file, serve } from "bun";
|
|
|
|
serve({
|
|
fetch(req: Request) {
|
|
const pathname = new URL(req.url).pathname.substring(1);
|
|
|
|
// If the URL is empty, display this file.
|
|
if (pathname === "") {
|
|
return new Response(file(import.meta.url));
|
|
}
|
|
|
|
return new Response(file(pathname));
|
|
},
|
|
|
|
// 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: 3000, // number or string
|
|
hostname: "localhost", // defaults to 0.0.0.0
|
|
});
|