bun add @mionkit/bun @mionkit/router
import {initMionBun} from '@mionkit/bun';
import {routes} from './bun-routes.ts';
const server = Bun.serve({
port: 3000,
fetch: initMionBun(routes),
});
console.log(`Server running at http://localhost:${server.port}`);
import {Routes, route} from '@mionkit/router';
export const routes = {
sayHello: route((ctx, name: string): string => {
return `Hello ${name}!`;
}),
} satisfies Routes;
You can pass configuration options to initMionBun:
import {initMionBun} from '@mionkit/bun';
import {routes} from './bun-routes.ts';
const handler = initMionBun(routes, {
prefix: '/api', // API prefix
// ... other router options
});
export interface BunHttpOptions {
port: number;
/** Bun's native Server Options */
options: BunServeOptions;
/** Set of default response header to add to every response*/
defaultResponseHeaders: Record<string, string>;
/**
* 256KB by default, same as lambda payload
* @link https://docs.aws.amazon.com/lambda/latest/operatorguide/payload.html
* */
maxBodySize: number; // default 256KB
}