Skip to content

Commit 55a42ca

Browse files
committed
Fix IoC binding for windows and fix swagger, info and status routes
1 parent 2e2ebaf commit 55a42ca

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

src/core/ApiInfo.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as express from 'express';
2-
import * as path from 'path';
32
import { Environment } from './helpers/Environment';
43
import { SwaggerUI } from './SwaggerUI';
54
import { ApiMonitor } from './ApiMonitor';
@@ -8,7 +7,7 @@ import { ApiMonitor } from './ApiMonitor';
87
export class ApiInfo {
98

109
public static getRoute(): string {
11-
return path.join(process.env.APP_URL_PREFIX, process.env.API_INFO_ROUTE);
10+
return process.env.APP_URL_PREFIX + process.env.API_INFO_ROUTE;
1211
}
1312

1413
public setup(app: express.Application): void {

src/core/ApiMonitor.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import * as express from 'express';
22
import * as monitor from 'express-status-monitor';
3-
import * as path from 'path';
43
import { Environment } from './helpers/Environment';
54

65

76
export class ApiMonitor {
87

98
public static getRoute(): string {
10-
return path.join(process.env.MONITOR_ROUTE);
9+
return process.env.MONITOR_ROUTE;
1110
}
1211

1312
public setup(app: express.Application): void {

src/core/IoC.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Types, Core, Targets } from '../constants';
1313
import { events, EventEmitter } from './api/events';
1414
import { Logger } from './Logger';
1515
import { IocConfig } from '../config/IocConfig';
16+
import { getFolderwrapping } from './helpers/Path';
1617

1718

1819
export class IoC {
@@ -184,13 +185,13 @@ export class IoC {
184185
}
185186

186187
private getBasePath(): string {
187-
const baseFolder = __dirname.indexOf('/src/') >= 0 ? '/src/' : '/dist/';
188+
const baseFolder = __dirname.indexOf(getFolderwrapping('src')) >= 0 ? getFolderwrapping('src') : getFolderwrapping('dist');
188189
const baseRoot = __dirname.substring(0, __dirname.indexOf(baseFolder));
189190
return path.join(baseRoot, baseFolder, 'api');
190191
}
191192

192193
private getFiles(path: string, done: (files: any[]) => void): void {
193-
const isTypeScript = __dirname.indexOf('/src/') >= 0;
194+
const isTypeScript = __dirname.indexOf(getFolderwrapping('src')) >= 0;
194195
if (!isTypeScript) {
195196
path = path.replace('.ts', '.js');
196197
}

src/core/SwaggerUI.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ import * as express from 'express';
22
import * as path from 'path';
33
import * as swaggerUi from 'swagger-ui-express';
44
import { Environment } from './helpers/Environment';
5+
import { getFolderwrapping } from './helpers/Path';
56

67

78
export class SwaggerUI {
89

910
public static getRoute(): string {
10-
return path.join(process.env.APP_URL_PREFIX, process.env.SWAGGER_ROUTE);
11+
return process.env.APP_URL_PREFIX + process.env.SWAGGER_ROUTE;
1112
}
1213

1314
public setup(app: express.Application): void {
1415
if (Environment.isTruthy(process.env.SWAGGER_ENABLED)) {
15-
const baseFolder = __dirname.indexOf('/src/') >= 0 ? '/src/' : '/dist/';
16+
const baseFolder = __dirname.indexOf(getFolderwrapping('src')) >= 0 ? getFolderwrapping('src') : getFolderwrapping('dist');
1617
const basePath = __dirname.substring(0, __dirname.indexOf(baseFolder));
1718
const swaggerFile = require(path.join(basePath, process.env.SWAGGER_FILE));
18-
const packageJson = require(path.join(basePath, '/package.json'));
19+
const packageJson = require(path.join(basePath, 'package.json'));
1920

2021
// Add npm infos to the swagger doc
2122
swaggerFile.info = {

src/core/helpers/Path.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const isWindows = (): boolean => /^win/.test(process.platform);
2+
export const getFolderwrapping = (input: string): string => isWindows() ? `\\${input}\\` : `/${input}/`;

0 commit comments

Comments
 (0)