From b87da55b749cc0d41e62819b4d2230df889c0588 Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Fri, 26 May 2023 18:03:51 -0400 Subject: [PATCH] feat(app-express): pass hyper services to all middleware --- packages/app-express/deno.jsonc | 12 ++++-------- packages/app-express/main.ts | 13 +++++++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/app-express/deno.jsonc b/packages/app-express/deno.jsonc index 16ccfded..c27dc6aa 100644 --- a/packages/app-express/deno.jsonc +++ b/packages/app-express/deno.jsonc @@ -5,13 +5,9 @@ "harness": "deno run --no-check --no-lock -A --reload ./harness.ts" }, "fmt": { - "files": { - "include": ["./"] - }, - "options": { - "lineWidth": 100, - "singleQuote": true, - "semiColons": false - } + "include": ["./"], + "lineWidth": 100, + "singleQuote": true, + "semiColons": false } } diff --git a/packages/app-express/main.ts b/packages/app-express/main.ts index d02c663c..80061b32 100644 --- a/packages/app-express/main.ts +++ b/packages/app-express/main.ts @@ -1,9 +1,7 @@ import { mountServicesWith } from './api/mod.ts' -import { cors, express, helmet, R } from './deps.ts' +import { cors, express, helmet } from './deps.ts' import type { ErrorRouteHandler, HyperServices, Server } from './types.ts' -const { compose } = R - // All of these args need to be specified, or it won't be invoked on error const errorHandler: ErrorRouteHandler = (err, _req, res, _next) => { if (err) { @@ -27,9 +25,12 @@ export function main(services: HyperServices): Server { app.use(cors({ credentials: true })) if (services.middleware?.length) { - // deno-lint-ignore ban-ts-comment - // @ts-ignore - app = compose(...services.middleware)(app, services) + app = services.middleware + .reverse() + .reduce( + (app, middleware) => middleware(app, services), + app, + ) } app = mountServices(app)