Skip to content

Commit 67ae0c8

Browse files
committed
feat: enhance middleware application order in boot process
1 parent 0b14fff commit 67ae0c8

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

express/src/core/app.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,21 @@ export default class Application implements ArkstackRouterAwareCore<Express, unk
7979
// Load public assets
8080
await this.driver.mountPublicAssets(this.app, path.join(process.cwd(), 'public'))
8181

82+
// Apply global middleware
83+
for (const middleware of config(this.app).global) {
84+
await this.driver.applyMiddleware(this.app, middleware)
85+
}
86+
87+
// Apply before middleware
88+
for (const middleware of config(this.app).before) {
89+
await this.driver.applyMiddleware(this.app, middleware)
90+
}
91+
8292
// Bind the router
8393
await this.driver.bindRouter(this.app)
8494

85-
for (const middleware of config(this.app).global) {
95+
// Apply after middleware
96+
for (const middleware of config(this.app).after) {
8697
await this.driver.applyMiddleware(this.app, middleware)
8798
}
8899

h3/src/core/app.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,21 @@ export default class Application implements ArkstackRouterAwareCore<H3, unknown>
8787
// Load public assets
8888
await this.driver.mountPublicAssets(this.app, 'public')
8989

90+
// Apply global middleware
91+
for (const middleware of config(this.app).global) {
92+
await this.driver.applyMiddleware(this.app, middleware)
93+
}
94+
95+
// Apply before middleware
96+
for (const middleware of config(this.app).before) {
97+
await this.driver.applyMiddleware(this.app, middleware)
98+
}
99+
90100
// Bind the router
91101
await this.driver.bindRouter(this.app)
92102

93-
for (const middleware of config(this.app).global) {
103+
// Apply after middleware
104+
for (const middleware of config(this.app).after) {
94105
await this.driver.applyMiddleware(this.app, middleware)
95106
}
96107

0 commit comments

Comments
 (0)