Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit c046ed8

Browse files
fix: force change localhost (#977)
1 parent e16b53c commit c046ed8

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

cortex-js/src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AppModule } from './app.module';
44
import { fileManagerService } from './infrastructure/services/file-manager/file-manager.service';
55
import { ValidationPipe } from '@nestjs/common';
66
import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases';
7-
export const getApp = async () => {
7+
export const getApp = async (host?: string, port?: number) => {
88
const app = await NestFactory.create(AppModule, {
99
snapshot: true,
1010
cors: true,
@@ -64,7 +64,7 @@ export const getApp = async () => {
6464
'System',
6565
'Endpoints for stopping the Cortex API server, checking its status, and fetching system events.',
6666
)
67-
.addServer('http://127.0.0.1:1337')
67+
.addServer(`http://${host || '127.0.0.1'}:${port || 1337}`)
6868
.build();
6969
const document = SwaggerModule.createDocument(app, config);
7070

cortex-js/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { cleanLogs } from './utils/log';
1313
* Start the API server
1414
*/
1515
export async function start(host?: string, port?: number) {
16-
const app = await getApp();
16+
const app = await getApp(host, port);
1717
// getting port from env
1818
const sHost = host || process.env.CORTEX_JS_HOST || defaultCortexJsHost;
1919
const sPort = port || process.env.CORTEX_JS_PORT || defaultCortexJsPort;

cortex-js/src/infrastructure/commanders/cortex-command.commander.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export class CortexCommand extends CommandRunner {
9191

9292
this.host = options?.address || configApiServerHost || defaultCortexJsHost;
9393
this.port = options?.port || configApiServerPort || defaultCortexJsPort;
94+
if(this.host === 'localhost') {
95+
this.host = '127.0.0.1';
96+
}
9497
this.enginePort =
9598
Number(options?.enginePort) ||
9699
configCortexCppPort ||
@@ -134,7 +137,7 @@ export class CortexCommand extends CommandRunner {
134137
await fileManagerService.getConfig(dataFolderPath);
135138
}
136139
if (attach) {
137-
const app = await getApp();
140+
const app = await getApp(this.host, this.port);
138141
await app.listen(this.port, this.host);
139142
} else {
140143
await this.cortexUseCases.startServerDetached(this.host, this.port);

cortex-js/src/infrastructure/services/file-manager/file-manager.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class FileManagerService {
3636
private benchmarkFoldername = 'benchmark';
3737
private cortexEnginesFolderName = 'engines';
3838
private cortexTelemetryFolderName = 'telemetry';
39-
private configProfile = 'default';
39+
private configProfile = process.env.CORTEX_PROFILE || 'default';
4040

4141
/**
4242
* Get cortex configs
@@ -353,14 +353,17 @@ export class FileManagerService {
353353
config = configs?.[this.configProfile] ?? config;
354354
} catch {}
355355
return {
356-
host: config.apiServerHost ?? 'localhost',
356+
host: config.apiServerHost ?? '127.0.0.1',
357357
port: config.apiServerPort ?? 1337,
358358
};
359359
}
360360

361361
public setConfigProfile(profile: string) {
362362
this.configProfile = profile;
363363
}
364+
public getConfigProfile() {
365+
return this.configProfile;
366+
}
364367
public profileConfigExists(profile: string): boolean {
365368
const homeDir = os.homedir();
366369
const configPath = join(homeDir, this.configFile);

cortex-js/src/usecases/cortex/cortex.usecases.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export class CortexUsecases implements BeforeApplicationShutdown {
151151
env: {
152152
CORTEX_JS_HOST: host,
153153
CORTEX_JS_PORT: port.toString(),
154+
CORTEX_PROFILE: fileManagerService.getConfigProfile(),
154155
},
155156
});
156157
server.disconnect(); // closes the IPC channel

0 commit comments

Comments
 (0)