Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/reno/reno/router.ts>createRouter

A thin, testable routing library designed to sit on top of Deno's standard HTTP module
Latest
function createRouter
import { createRouter } from "https://deno.land/x/reno@v2.0.105/reno/router.ts";

Creates a Reno router for the given routes, which can then be invoked as an async function when Deno's HTTP server receives a request:

import { serve } from "https://deno.land/std@0.192.0/http/server.ts";
import { createRouter } from "https://deno.land/x/reno@<VERSION>/reno/mod.ts";
import { routes } from "./routes.ts";

const PORT = ":8000";

const router = createRouter(routes);

console.log(`Listening for requests on ${PORT}...`);

await serve(
  async req => {
    try {
      return await router(req);
    } catch (e) {
      return mapToErrorResponse(e);
    }
  },
  {
    port: PORT,
  },
);