From df74cde2a0145104ad6858e9629d7789b08f7b99 Mon Sep 17 00:00:00 2001 From: Rafael Date: Wed, 15 Feb 2023 15:18:49 -0300 Subject: [PATCH] feat(core): add support to named groups --- packages/core/router/router-explorer.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/core/router/router-explorer.ts b/packages/core/router/router-explorer.ts index 843ca5d2d1a..e7bbc6db1f8 100644 --- a/packages/core/router/router-explorer.ts +++ b/packages/core/router/router-explorer.ts @@ -292,7 +292,13 @@ export class RouterExplorer { for (const exp of hostRegExps) { const match = hostname.match(exp.regexp); if (match) { - exp.keys.forEach((key, i) => (req.hosts[key.name] = match[i + 1])); + if (exp.keys.length > 0) { + exp.keys.forEach((key, i) => (req.hosts[key.name] = match[i + 1])); + } else if (exp.regexp && match.groups) { + for (const groupName in match.groups) { + req.hosts[groupName] = match.groups[groupName]; + } + } return handler(req, res, next); } }