-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support midway global middleware use id
- Loading branch information
1 parent
ce0e06a
commit 8dc9ae3
Showing
14 changed files
with
234 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/web/test/fixtures/feature/base-app-middleware/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "ali-demo-global-middleware" | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/web/test/fixtures/feature/base-app-middleware/src/config/config.default.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const keys = 'key'; | ||
|
||
export const hello = { | ||
a: 1, | ||
b: 2, | ||
d: [1, 2, 3], | ||
}; | ||
|
||
export const middleware = ['globalMiddleware2']; |
5 changes: 5 additions & 0 deletions
5
packages/web/test/fixtures/feature/base-app-middleware/src/config/config.unittest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
exports.hello = { | ||
b: 4, | ||
c: 3, | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/web/test/fixtures/feature/base-app-middleware/src/config/plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
'static': false | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/web/test/fixtures/feature/base-app-middleware/src/configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { App, Configuration } from '@midwayjs/decorator'; | ||
import { IMidwayWebApplication } from '../../../../../src'; | ||
|
||
@Configuration({ | ||
importConfigs: [ | ||
'./config' | ||
] | ||
}) | ||
export class ContainerConfiguration { | ||
|
||
@App() | ||
app: IMidwayWebApplication; | ||
|
||
async onReady() { | ||
this.app.use(await this.app.generateMiddleware('globalMiddleware1')); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/web/test/fixtures/feature/base-app-middleware/src/controller/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Controller, Get, Inject, Provide, } from '@midwayjs/decorator'; | ||
import { IMidwayWebContext } from '../../../../../../src'; | ||
|
||
@Provide() | ||
@Controller('/', { middleware: ['globalMiddleware3'] }) | ||
export class APIController { | ||
@Inject() | ||
ctx: IMidwayWebContext; | ||
|
||
@Get('/', { middleware: ['globalMiddleware4'] }) | ||
async home() { | ||
return this.ctx.state['a'] + this.ctx.state['b'] + this.ctx.state['c'] + this.ctx.state['d']; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
packages/web/test/fixtures/feature/base-app-middleware/src/middleware/global.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Provide } from '@midwayjs/decorator'; | ||
import { IMidwayWebContext } from '../../../../../../src'; | ||
|
||
@Provide() | ||
export class GlobalMiddleware1 { | ||
resolve() { | ||
return async (ctx: IMidwayWebContext, next) => { | ||
ctx.state.a = '1111'; | ||
await next(); | ||
} | ||
} | ||
} | ||
|
||
@Provide() | ||
export class GlobalMiddleware2 { | ||
resolve() { | ||
return async (ctx: IMidwayWebContext, next) => { | ||
ctx.state.b = '2222'; | ||
await next(); | ||
} | ||
} | ||
} | ||
|
||
@Provide() | ||
export class GlobalMiddleware3 { | ||
resolve() { | ||
return async (ctx: IMidwayWebContext, next) => { | ||
ctx.state.c = '3333'; | ||
await next(); | ||
} | ||
} | ||
} | ||
|
||
@Provide() | ||
export class GlobalMiddleware4 { | ||
resolve() { | ||
return async (ctx: IMidwayWebContext, next) => { | ||
ctx.state.d = '4444'; | ||
await next(); | ||
} | ||
} | ||
} |