app.serve
The app.serve() method is the core handler for processing HTTP requests in TezX when running in Bun. It bridges Bun's server with your application logic, executing middleware and route handlers seamlessly.
What It Does
- Accepts a Fetch API-compatible
Request. - Receives Bun’s
Serverinstance for runtime context. - Executes your defined middleware chain.
- Dispatches route handlers.
- Returns a
Responseobject for Bun to send.
This provides a plug-and-play integration with Bun without any additional setup.
Method Signature
public async serve(req: Request, server: Bun.Server): Promise<Response>req— The native Bun/Fetch API request object.server— Bun server instance, used internally for request context if needed.
Usage Example (Bun)
import { wsHandlers } from "tezx/ws";
// Minimal integration
Bun.serve({
port: 3000,
fetch: (req ,server) => app.serve(req, server)
});
// Full Bun server with WebSocket support
Bun.serve({
port: 3000,
fetch: app.serve,
websocket: wsHandlers({})
});
app.serve()in Bun is your direct bridge between the server runtime and application logic — fast, simple, and fully integrated.
Initialization
TezX is a high-performance, middleware-first server framework designed exclusively for the Bun runtime.
Context
The Context class is the central abstraction for handling requests and responses in TezX. It wraps a request, manages headers, status codes, body, and provides helper methods for sending different types of responses including text, HTML, JSON, files, and redirects.