Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/lib/rest/foundation/controller-scanner.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { join } from 'path';
import { Type } from '../../interfaces';
import {
CONTROLLER_KEY,
METHOD_KEY,
METHOD_PATH,
} from '../http-server/constants';
import { HttpRoute } from '../http-server/interfaces';
import { joinRoute } from '../helpers';

export class ControllerScanner {
handle(cls: Type<any>): HttpRoute[] {
Expand All @@ -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 });
}

Expand Down
2 changes: 0 additions & 2 deletions packages/core/lib/rest/foundation/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
2 changes: 2 additions & 0 deletions packages/core/lib/rest/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const joinRoute = (...paths: string[]) =>
paths.join('/').replace(/[/]+/g, '/');
6 changes: 3 additions & 3 deletions packages/core/lib/rest/http-server/route-explorer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DiscoveryService, MetadataScanner, ModuleRef } from '@nestjs/core';
import { join } from 'path';
import { HttpRoute } from './interfaces';
import {
Request,
Expand All @@ -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<IntentGuard>[] = [];
Expand Down Expand Up @@ -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 };
}

Expand Down Expand Up @@ -189,7 +189,7 @@ export class RouteExplorer {

return {
method: pathMethod,
path: join('/', controllerKey, methodPath),
path: joinRoute('/', controllerKey, methodPath),
httpHandler: cb,
};
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/lib/rest/http-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,15 +87,15 @@ export class HyperServer {
...staticServeConfig,
});

const httpPath = join(
const httpPath = joinRoute(
'/',
staticServeConfig.httpPath.replace('*', ''),
'/*',
);

this.hyper.get(httpPath, (req, res) => {
const path = Str.replaceFirst(
req.path.replace(join('/', staticServeConfig.httpPath), ''),
req.path.replace(joinRoute('/', staticServeConfig.httpPath), ''),
'/',
'',
);
Expand Down
Loading