Skip to content

Commit

Permalink
[routing-utils] Update routes schema for new property (vercel#6860)
Browse files Browse the repository at this point in the history
Adds an additional property for the `routes` schema. 

### Related Issues

N/A

### 📋 Checklist

<!--
  Please keep your PR as a Draft until the checklist is complete
-->

#### Tests

- [x] The code changed/added as part of this PR has been covered with tests
- [x] All tests pass locally with `yarn test-unit`

#### Code Review

- [ ] This PR has a concise title and thorough description useful to a reviewer
- [ ] Issue from task tracker has a link to this PR
  • Loading branch information
ijjk authored Oct 18, 2021
1 parent be5c0da commit dccacc4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/routing-utils/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ export const routesSchema = {
},
},
},
middleware: {
type: 'object',
required: ['id', 'type'],
additionalProperties: false,
properties: {
id: {
type: 'string',
maxLength: 256,
},
type: {
type: 'string',
maxLength: 32,
enum: ['v8-worker'],
},
},
},
has: hasSchema,
},
},
Expand Down
4 changes: 4 additions & 0 deletions packages/routing-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export type Source = {
redirect?: Record<string, string>;
cookie?: string;
};
middleware?: {
id: string;
type: 'v8-worker';
};
};

export type Handler = {
Expand Down
7 changes: 7 additions & 0 deletions packages/routing-utils/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ describe('normalizeRoutes', () => {
headers: { 'Cache-Control': 'no-cache' },
dest: '/blog',
},
{
src: '^/.*$',
middleware: {
id: '1',
type: 'v8-worker',
},
},
{ handle: 'filesystem' },
{ src: '^/(?<slug>[^/]+)$', dest: 'blog?slug=$slug' },
{ handle: 'hit' },
Expand Down
14 changes: 14 additions & 0 deletions packages/routing-utils/test/merge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,13 @@ test('mergeRoutes ensure beforeFiles comes after redirects (check)', () => {
check: true,
override: true,
},
{
src: '^/.*$',
middleware: {
id: '1',
type: 'v8-worker',
},
},
{
handle: 'filesystem',
},
Expand All @@ -508,6 +515,13 @@ test('mergeRoutes ensure beforeFiles comes after redirects (check)', () => {
check: true,
override: true,
},
{
src: '^/.*$',
middleware: {
id: '1',
type: 'v8-worker',
},
},
{ handle: 'filesystem' },
{ src: '^/404$', dest: '/404', status: 404, check: true },
];
Expand Down

0 comments on commit dccacc4

Please sign in to comment.