diff --git a/packages/core/lib/rest/foundation/controller-scanner.ts b/packages/core/lib/rest/foundation/controller-scanner.ts index 6dc0457..af5265e 100644 --- a/packages/core/lib/rest/foundation/controller-scanner.ts +++ b/packages/core/lib/rest/foundation/controller-scanner.ts @@ -1,4 +1,3 @@ -import { join } from 'path'; import { Type } from '../../interfaces'; import { CONTROLLER_KEY, @@ -6,6 +5,7 @@ import { METHOD_PATH, } from '../http-server/constants'; import { HttpRoute } from '../http-server/interfaces'; +import { joinRoute } from '../helpers'; export class ControllerScanner { handle(cls: Type): HttpRoute[] { @@ -26,7 +26,7 @@ export class ControllerScanner { if (!pathMethod) continue; - const fullHttpPath = join(controllerKey, methodPath); + const fullHttpPath = joinRoute(controllerKey, methodPath); routes.push({ method: pathMethod, path: fullHttpPath }); } diff --git a/packages/core/lib/rest/foundation/server.ts b/packages/core/lib/rest/foundation/server.ts index e07124e..e4ccb3b 100644 --- a/packages/core/lib/rest/foundation/server.ts +++ b/packages/core/lib/rest/foundation/server.ts @@ -22,8 +22,6 @@ import { HttpExecutionContext } from '../http-server/contexts/http-execution-con import { ExecutionContext } from '../http-server/contexts/execution-context'; import { Response } from '../http-server/response'; import { RouteExplorer } from '../http-server/route-explorer'; -import { readSync } from 'fs-extra'; -import { join } from 'path'; const signals = ['SIGTERM', 'SIGINT', 'SIGUSR2']; diff --git a/packages/core/lib/rest/helpers.ts b/packages/core/lib/rest/helpers.ts new file mode 100644 index 0000000..20e1b86 --- /dev/null +++ b/packages/core/lib/rest/helpers.ts @@ -0,0 +1,2 @@ +export const joinRoute = (...paths: string[]) => + paths.join('/').replace(/[/]+/g, '/'); diff --git a/packages/core/lib/rest/http-server/route-explorer.ts b/packages/core/lib/rest/http-server/route-explorer.ts index fb9321a..74e026d 100644 --- a/packages/core/lib/rest/http-server/route-explorer.ts +++ b/packages/core/lib/rest/http-server/route-explorer.ts @@ -1,5 +1,4 @@ import { DiscoveryService, MetadataScanner, ModuleRef } from '@nestjs/core'; -import { join } from 'path'; import { HttpRoute } from './interfaces'; import { Request, @@ -23,6 +22,7 @@ import { IntentGuard } from '../foundation/guards/base-guard'; import { IntentMiddleware } from '../foundation/middlewares/middleware'; import { IntentExceptionFilter } from '../../exceptions/base-exception-handler'; import { Reply } from './reply'; +import { joinRoute } from '../helpers'; export class RouteExplorer { globalGuards: Type[] = []; @@ -104,7 +104,7 @@ export class RouteExplorer { console.log(instance.constructor); console.log(controllerKey, methodPath, pathMethod, key); - const fullHttpPath = join(controllerKey, methodPath); + const fullHttpPath = joinRoute(controllerKey, methodPath); return { method: pathMethod, path: fullHttpPath }; } @@ -189,7 +189,7 @@ export class RouteExplorer { return { method: pathMethod, - path: join('/', controllerKey, methodPath), + path: joinRoute('/', controllerKey, methodPath), httpHandler: cb, }; } diff --git a/packages/core/lib/rest/http-server/server.ts b/packages/core/lib/rest/http-server/server.ts index 463b770..d0192be 100644 --- a/packages/core/lib/rest/http-server/server.ts +++ b/packages/core/lib/rest/http-server/server.ts @@ -4,9 +4,9 @@ import { IntentMiddleware } from '../foundation/middlewares/middleware'; import { Validator } from '../../validator'; import { ConfigService } from '../../config'; import LiveDirectory from 'live-directory'; -import { join } from 'path'; import { FileNotFoundException } from '../../exceptions/file-not-found-exception'; import { Str } from '../../utils'; +import { joinRoute } from '../helpers'; export class HyperServer { protected hyper: HyperExpress.Server; @@ -87,7 +87,7 @@ export class HyperServer { ...staticServeConfig, }); - const httpPath = join( + const httpPath = joinRoute( '/', staticServeConfig.httpPath.replace('*', ''), '/*', @@ -95,7 +95,7 @@ export class HyperServer { this.hyper.get(httpPath, (req, res) => { const path = Str.replaceFirst( - req.path.replace(join('/', staticServeConfig.httpPath), ''), + req.path.replace(joinRoute('/', staticServeConfig.httpPath), ''), '/', '', );