Bun integration
TSDL works natively with Bun (opens in a new tab).
Installation
Make sure you have a server ready. Then run:
bun install @tsdl/bun
If you don't have a router
, read the getting started guide
Add this to your bun server:
server.ts
import { bunTSDL } from "@tsdl/bun";
Bun.serve({
port: 9000,
fetch(req) {
const url = new URL(req.url);
if (url.pathname.startsWith("/tsdl")) {
return bunTSDL(
router,
req,
(content, status) =>
new Response(content, {
status,
headers: {
"Access-Control-Allow-Origin": "*", // TODO: change this
},
})
);
}
/* ... */
return new Response("404!");
},
});
Providing base context
The base context is the basis for subsequent (if any) contexts and the type is provided as a generic argument when creating a TSDL instance
bunTSDL(
router,
req,
responseCb,
ctx // <--- this is where you provide your base context.
);