Skip to content

Commit

Permalink
feat(mold): add usesAt for specific middleware route
Browse files Browse the repository at this point in the history
  • Loading branch information
nampdn committed Nov 13, 2019
1 parent 2f18baf commit 0c8ab22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ const ExpressServer = portion<WhenRequest, Application, ExpressMold>({
},
whenInitialized: flow({
bootstrap: ({ context: expressApp, next, mold }: any) => {
const { port, uses } = mold
const { port, uses, usesAt } = mold as ExpressMold
if (uses && uses.length > 0) {
for (const middleware of uses) expressApp.use(middleware)
}
if (usesAt && usesAt.length > 0) {
for (const use of usesAt) {
const { route, middleware } = use
expressApp.use(route, middleware)
}
}
expressApp.listen(port, function() {
next({ port })
})
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export interface WhenCustomRoute extends WhenRequest {
mountPoint: string
}

export interface RouteUseAt {
route: string
middleware: any
}

export interface RouteConfig {
mountPoint: string
/**
Expand All @@ -28,4 +33,5 @@ export interface ExpressMold {
port?: number
uses?: any[]
routes: ExpressMoldRoute
usesAt?: RouteUseAt[]
}

0 comments on commit 0c8ab22

Please sign in to comment.