Skip to content

Commit

Permalink
[now dev] Use empty string for missing matches (#2376)
Browse files Browse the repository at this point in the history
Rather than `undefined`. This matches the behavior in production.

Fixes #2375.
  • Loading branch information
TooTallNate committed Jun 5, 2019
1 parent 9d110bd commit a31c29f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit a31c29f

Please sign in to comment.