Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Adds pipe() for creating reusable route logic

Compare
Choose a tag to compare
@jamesseanwright jamesseanwright released this 18 Nov 19:20
· 465 commits to master since this release

Adds pipe() for creating reusable route logic. It's conceptually similar to Express' middleware pattern, but leverages function piping to create reusable, higher-order route handlers:

import { createRouteMap, jsonResponse, pipe } from "https://raw.githubusercontent.com/jamesseanwright/reno/v0.6.0/reno/mod.ts";

const withCaching = pipe(
  (req, res) => {
    res.headers.append("Cache-Control", "max-age=86400");
    return res;
  },
  (req, res) => ({
    ...res,
    cookies: new Map<string, string>([["requested_proto", req.proto]])
  })
);

const home = withCaching(() =>
  jsonResponse({
    foo: "bar",
    isLol: true
  })
);

export const routes = createRouteMap([["/", home]]);