Function handleRoutes

Handles incoming requests by matching them to the appropriate route and processing the response.

It is used with Bun.serve in the start() function to handle incoming requests and generate the appropriate response.

  • Parameters

    • routes: Route[]

      An array of available routes.

    Returns Promise<((request: Request) => Promise<Response>)>

    A function that takes an HTTP request and returns the appropriate response.

    Example usage:

    import { router, text, handleRoutes, log } from "@pulsar-http/core";

    const routes = [
    router.get('/api/users', async () => text('User List')),
    ];


    (async () => {
    const handler = await handleRoutes(routes);

    // Fake a request and get the response
    const response = await handler(new Request('http://localhost:3000/api/users'));
    const text = await response.text();

    log(text); // Output: "[current datetime]: User List"
    })();