Skip to content

Commit

Permalink
feat(app-express): pass hyper services to all middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed May 26, 2023
1 parent daeb3b0 commit b87da55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
12 changes: 4 additions & 8 deletions packages/app-express/deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
13 changes: 7 additions & 6 deletions packages/app-express/main.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit b87da55

Please sign in to comment.