Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[now dev] Use empty string for missing matches #2376

Merged
merged 1 commit into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/dev/lib/dev-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function resolveRouteParameters(
// match up with the RegExp group matches
matchIndex++;
}
return match[matchIndex];
return match[matchIndex] || '';
});
}

Expand Down
19 changes: 19 additions & 0 deletions test/dev-router.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ test('[dev-router] named groups', async t => {
});
});

test('[dev-router] optional named groups', async t => {
const routesConfig = [{
src: '/api/hello(/(?<name>[^/]+))?',
dest: '/api/functions/hello/index.js?name=$name'
}];
const result = await devRouter('/api/hello', 'GET', routesConfig);

t.deepEqual(result, {
found: true,
dest: '/api/functions/hello/index.js',
status: undefined,
headers: undefined,
uri_args: { name: '' },
matched_route: routesConfig[0],
matched_route_idx: 0,
userDest: true
});
});

test('[dev-router] proxy_pass', async t => {
const routesConfig = [{ src: '/proxy', dest: 'https://zeit.co' }];

Expand Down