Hattip adapter for Bun.
Assuming you have your Hattip handler defined in handler.js
and your static assets are in the public
directory, create an entry-bun.js
file like the following and use bun entry-bun.js
to run it:
import bunAdapter from "@hattip/adapter-bun";
import handler from "./handler.js";
import url from "node:url";
import path from "node:path";
const dir = path.resolve(
path.dirname(url.fileURLToPath(new URL(import.meta.url))),
"public",
);
export default bunAdapter(handler, { staticDir: dir });
You can leave out the staticDir
option if you don't want to serve static assets.
staticDir
: The directory to serve static assets from. Leave undefined to not serve static assets.trustProxy
: Whether to trust theX-Forwarded-For
header.
The remaining options (port
, hostname
etc.) are passed to Bun.serve.
export interface BunPlatformInfo {
/** Platform name */
name: "bun";
/** Bun server instance */
server: Server;
}
The ctx.env()
function is implemented using process.env
.
Bun support is preliminary and Bun itself is in early development:
- No way to determine the IP address of the client when
trustProxy
is false. - No streaming, everything is cached.