serve
Reference
serve(options: ServeOptions): { port: number; hostname: string; server: Server; }
The serve
function is used to start the Bun.js server and listen for incoming requests.
Example usage:
In the next example, we use the serve
function to start the Bun.js server.
import { getServeOptions, serve } from "brisa/server";
const serveOptions = await getServeOptions();
const { server, port, hostname } = serve({
...serveOptions,
fetch(req, server) {
// Your implementation here ...
// Brisa handler
return serveOptions.fetch(req, server);
},
port: 3001,
});
console.log(
"Server ready ๐ฅณ",
`listening on http://${hostname}:${port}...`,
);
It only makes sense to use it if you need a custom server for extra things from the serve but if you start the server in the same way as Brisa.
Types
export function serve(options: ServeOptions): {
port: number;
hostname: string;
server: Server; // Bun.js server (Bun.serve)
};