Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: middleware disable in express (#2187)
- Loading branch information
1 parent
ee7606e
commit 8cad157
Showing
11 changed files
with
194 additions
and
14 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
3 changes: 3 additions & 0 deletions
3
packages/web-express/test/fixtures/base-app-disable/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" | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/web-express/test/fixtures/base-app-disable/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 @@ | ||
'use strict'; | ||
|
||
export const keys = 'key'; | ||
|
||
export const hello = { | ||
a: 1, | ||
b: 2, | ||
d: [1, 2, 3], | ||
}; | ||
|
||
export const bodyParser = { | ||
enable: false, | ||
} | ||
|
||
export const session = { | ||
enable: false, | ||
} | ||
|
||
export const cookieParser = { | ||
enable: false, | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/web-express/test/fixtures/base-app-disable/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, | ||
}; |
24 changes: 24 additions & 0 deletions
24
packages/web-express/test/fixtures/base-app-disable/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,24 @@ | ||
import { Configuration, App } from '@midwayjs/decorator'; | ||
import { join } from 'path'; | ||
import { IMidwayExpressApplication, Context } from '../../../../src'; | ||
|
||
@Configuration({ | ||
imports: [ | ||
require('../../../../src') | ||
], | ||
importConfigs: [ | ||
join(__dirname, './config') | ||
] | ||
}) | ||
export class ContainerConfiguration { | ||
|
||
@App() | ||
app: IMidwayExpressApplication; | ||
|
||
async onReady() { | ||
this.app.use((req: Context, res, next) => { | ||
console.log('invoke middleware in ready'); | ||
next(); | ||
}); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
packages/web-express/test/fixtures/base-app-disable/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,82 @@ | ||
import { | ||
Controller, | ||
Post, | ||
Get, | ||
Inject, | ||
Query, | ||
Body, | ||
HttpCode, | ||
Redirect, | ||
SetHeader, | ||
Logger, | ||
Headers, | ||
} from '@midwayjs/decorator'; | ||
import { UserService } from '../service/user'; | ||
import { Context } from '../../../../../src'; | ||
import { Response } from 'express'; | ||
|
||
@Controller('/api') | ||
export class APIController { | ||
|
||
@Inject() | ||
ctx: Context; | ||
|
||
@Inject() | ||
req: Context; | ||
|
||
@Inject() | ||
res: Response; | ||
|
||
@Logger() | ||
logger; | ||
|
||
@Inject('logger') | ||
ctxLogger; | ||
|
||
@Inject() | ||
userService: UserService; | ||
|
||
@Get('/set_header') | ||
@SetHeader('bbb', 'aaa') | ||
@SetHeader({ | ||
'ccc': 'ddd' | ||
}) | ||
async homeSet() { | ||
return 'bbb'; | ||
} | ||
|
||
@Post() | ||
async postData(@Body('bbbbb') bbbb) { | ||
return bbbb; | ||
} | ||
|
||
@Get('/', { middleware: [] }) | ||
@HttpCode(201) | ||
async home(@Query('name') name: string) { | ||
this.ctx.logger.info('my home router'); | ||
this.ctxLogger.info('another ctx logger'); | ||
this.logger.warn('my home warn router') | ||
return 'hello world,' + name; | ||
} | ||
|
||
@Get('/204') | ||
async status204() { | ||
// empty | ||
} | ||
|
||
@Get('/login') | ||
@Redirect('/') | ||
async redirect() { | ||
} | ||
|
||
@Get('/ctx-body') | ||
async getCtxBody() { | ||
this.res.send('ctx-body'); | ||
} | ||
|
||
@Get('/header-upper') | ||
async getHeaderWithUppercase(@Headers('X-ABC') abc) { | ||
return abc; | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
packages/web-express/test/fixtures/base-app-disable/src/service/user.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 { Provide } from '@midwayjs/decorator'; | ||
|
||
@Provide() | ||
export class UserService { | ||
async hello(name) { | ||
return { | ||
name, | ||
}; | ||
} | ||
} |
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