-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
132 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { AppCtx, launchFixture } from 'shuvi-test-utils'; | ||
import got from 'got'; | ||
|
||
jest.setTimeout(5 * 60 * 1000); | ||
|
||
describe('Middleware config test', () => { | ||
let ctx: AppCtx; | ||
|
||
beforeAll(async () => { | ||
ctx = await launchFixture('middlewares-config'); | ||
}); | ||
|
||
afterAll(async () => { | ||
await ctx.close(); | ||
}); | ||
|
||
it('should get correct headers when visited /', async () => { | ||
const res = await got.get(ctx.url('/')); | ||
|
||
const inIndex = res.headers['in-index']; | ||
const inA = res.headers['in-a']; | ||
const inA1 = res.headers['in-a1']; | ||
const correctResult = inIndex && !inA && !inA1; | ||
const mOrder = res.headers['m-order']; | ||
|
||
expect(correctResult).toBeTruthy(); | ||
expect(mOrder).toBe('-index'); | ||
}); | ||
|
||
it('should get correct headers when visited /a', async () => { | ||
const res = await got.get(ctx.url('/a')); | ||
|
||
const inIndex = res.headers['in-index']; | ||
const inA = res.headers['in-a']; | ||
const inA1 = res.headers['in-a1']; | ||
const correctResult = !inIndex && inA && !inA1; | ||
const mOrder = res.headers['m-order']; | ||
|
||
expect(correctResult).toBeTruthy(); | ||
expect(mOrder).toBe('-a'); | ||
}); | ||
|
||
it('should get correct headers when visited /a/a1', async () => { | ||
const res = await got.get(ctx.url('/a/a1')); | ||
|
||
const inIndex = res.headers['in-index']; | ||
const inA = res.headers['in-a']; | ||
const inA1 = res.headers['in-a1']; | ||
const correctResult = !inIndex && inA && inA1; | ||
const mOrder = res.headers['m-order']; | ||
|
||
expect(correctResult).toBeTruthy(); | ||
|
||
expect(mOrder).toBe('-a-a1'); | ||
}); | ||
}); |
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 @@ | ||
export default { | ||
ssr: true, | ||
middlewareRoutes: [ | ||
{ | ||
path: '/a/:rest*', | ||
middlewares: ['a/m.js'] | ||
}, | ||
{ | ||
path: '/a/a1', | ||
middlewares: ['a/a1/m.js'] | ||
}, | ||
{ | ||
path: '/', | ||
middlewares: ['m.js'] | ||
} | ||
] | ||
}; |
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 @@ | ||
export function middleware(req, res, next) { | ||
const mOrder = res.getHeader('m-order') || ''; | ||
res.setHeader('m-order', mOrder + '-a1'); | ||
res.setHeader('in-a1', '1'); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Index() { | ||
return <div>index</div>; | ||
} |
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 @@ | ||
export function middleware(req, res, next) { | ||
const mOrder = res.getHeader('m-order') || ''; | ||
res.setHeader('m-order', mOrder + '-a'); | ||
res.setHeader('in-a', '1'); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Index() { | ||
return <div>index</div>; | ||
} |
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 @@ | ||
export function middleware(req, res, next) { | ||
res.setHeader('in-index', '1'); | ||
res.setHeader('m-order', '-index'); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Index() { | ||
return <div>index</div>; | ||
} |