-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: load egg router before midway container ready (#909)
- Loading branch information
1 parent
460bb48
commit 4640674
Showing
13 changed files
with
127 additions
and
0 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
3 changes: 3 additions & 0 deletions
3
packages/web/test/fixtures/issue/base-app-egg-router/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" | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/web/test/fixtures/issue/base-app-egg-router/src/app/controller/eggTest.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 @@ | ||
import { Controller } from 'egg'; | ||
|
||
export default class EggTestController extends Controller { | ||
public test() { | ||
this.ctx.body = { | ||
data: '中间件运行结果:' + this.ctx.test, | ||
}; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/web/test/fixtures/issue/base-app-egg-router/src/app/router.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,10 @@ | ||
import { Application } from 'egg'; | ||
|
||
export default (app: Application) => { | ||
const { controller, router } = app; | ||
|
||
router.get( | ||
'/api/egg-test', | ||
controller.eggTest.test, | ||
); | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/web/test/fixtures/issue/base-app-egg-router/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,21 @@ | ||
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg'; | ||
|
||
export type DefaultConfig = PowerPartial<EggAppConfig>; | ||
|
||
export default (appInfo: EggAppInfo) => { | ||
const config = {} as DefaultConfig; | ||
|
||
// use for cookie sign key, should change to your own and keep security | ||
config.keys = appInfo.name + '_1615306124396_5113'; | ||
|
||
// add your config here | ||
config.middleware = ['clientCheckerMiddleware']; | ||
|
||
config.midwayFeature = { | ||
// true 代表使用 midway logger | ||
// false 或者为空代表使用 egg-logger | ||
replaceEggLogger: true | ||
} | ||
|
||
return config; | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/web/test/fixtures/issue/base-app-egg-router/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,3 @@ | ||
export const security = { | ||
csrf: false | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/web/test/fixtures/issue/base-app-egg-router/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,5 @@ | ||
import { EggPlugin } from 'egg'; | ||
export default { | ||
logrotator: false, // disable when use @midwayjs/logger | ||
static: false, | ||
} as EggPlugin; |
13 changes: 13 additions & 0 deletions
13
packages/web/test/fixtures/issue/base-app-egg-router/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,13 @@ | ||
import { App, Configuration } from '@midwayjs/decorator'; | ||
import { ILifeCycle } from '@midwayjs/core'; | ||
import { Application } from 'egg'; | ||
|
||
@Configuration() | ||
export class ContainerLifeCycle implements ILifeCycle { | ||
|
||
@App() | ||
app: Application; | ||
|
||
async onReady() { | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/web/test/fixtures/issue/base-app-egg-router/src/controller/home.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 { Controller, Get, Inject, Provide } from '@midwayjs/decorator'; | ||
import { Context } from 'egg'; | ||
|
||
@Provide() | ||
@Controller('/') | ||
export class HomeController { | ||
|
||
@Inject() | ||
ctx: Context; | ||
|
||
@Get('/') | ||
async home() { | ||
return { | ||
data: '中间件运行结果:' + this.ctx.test, | ||
}; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/web/test/fixtures/issue/base-app-egg-router/src/interface.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,6 @@ | ||
/** | ||
* @description User-Service parameters | ||
*/ | ||
export interface IUserOptions { | ||
uid: number; | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/web/test/fixtures/issue/base-app-egg-router/src/middleware/client_checker.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,14 @@ | ||
import { Provide } from '@midwayjs/decorator'; | ||
import { IWebMiddleware, IMidwayWebNext } from '../../../../../../src'; | ||
import { Context } from 'egg'; | ||
|
||
@Provide() | ||
export class ClientCheckerMiddleware implements IWebMiddleware { | ||
resolve() { | ||
return async (ctx: Context, next: IMidwayWebNext) => { | ||
console.log('运行了 ClientCheckerMiddleware'); | ||
ctx.test = '来自 ClientCheckerMiddleware 的值'; | ||
await next(); | ||
}; | ||
} | ||
} |
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