From 2f7037b5643706773c511ac2207e50838fbd54e5 Mon Sep 17 00:00:00 2001 From: GabrielRoger07 Date: Thu, 5 Sep 2024 18:31:38 -0300 Subject: [PATCH] Resolvendo issues de manutenibilidade --- src/utils.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 4afb9e6..e5f6fcb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -14,22 +14,25 @@ const getUrl = (req: Request) => { const queryString = parts[1]; const updatedPath = parts[0]; - return baseUrl + updatedPath + (queryString ? '?' + queryString : '') + return baseUrl + updatedPath + (queryString ? '?' + queryString : ''); } +const videoServiceRegex = /\/videoservice/; +const userServiceRegex = /\/userservice/; +const adminServiceRegex = /\/adminservice/; + const getHost = (req: Request) => { - if (req.baseUrl.match('/videoservice')) { + if (videoServiceRegex.exec(req.baseUrl)) { console.log("VIDEO CALLED"); return VIDEO_API_URL; - } else if (req.baseUrl.match('/userservice')) { + } else if (userServiceRegex.exec(req.baseUrl)) { console.log("USER CALLED"); return USER_API_URL; - } else if (req.baseUrl.match('/adminservice')) { + } else if (adminServiceRegex.exec(req.baseUrl)) { console.log("ADMIN CALLED"); return ADMIN_API_URL; - } - else { - return '' + } else { + return ''; } }