Skip to main content

Usage example

import { Application } from "https://deno.land/x/oak@v9.0.1/mod.ts";
import { StaticRouter } from "./mod.ts";

const app = new Application();
const router = new StaticRouter();

await router.statics({
    absolute: "./path/to/views",
    relative: "/",
});

await router.statics({
    absolute: "./path/to/styles",
    relative: "css",
});

await router.statics({
    absolute: "./path/to/scripts",
    relative: "js",
});

app.use(await router.routes);
await app.listen({ port: 8080 });

The class StaticRouter receives a list of paths and provides a number of methods:

  • statics

    Allows to declare a static route and receives an argument of type path.

  • routes

    it is an asynchronous getter that returns the routes already configured.

The Path type contains information about the paths to use:

  • absolute

    defines the absolute path of the file or folder

  • relative

    defines the relative path within the router

Dependencies