Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: force change localhost #977

Merged
merged 1 commit into from
Aug 5, 2024
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 cortex-js/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AppModule } from './app.module';
import { fileManagerService } from './infrastructure/services/file-manager/file-manager.service';
import { ValidationPipe } from '@nestjs/common';
import { TelemetryUsecases } from './usecases/telemetry/telemetry.usecases';
export const getApp = async () => {
export const getApp = async (host?: string, port?: number) => {
const app = await NestFactory.create(AppModule, {
snapshot: true,
cors: true,
Expand Down Expand Up @@ -64,7 +64,7 @@ export const getApp = async () => {
'System',
'Endpoints for stopping the Cortex API server, checking its status, and fetching system events.',
)
.addServer('http://127.0.0.1:1337')
.addServer(`http://${host || '127.0.0.1'}:${port || 1337}`)
.build();
const document = SwaggerModule.createDocument(app, config);

Expand Down
2 changes: 1 addition & 1 deletion cortex-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { cleanLogs } from './utils/log';
* Start the API server
*/
export async function start(host?: string, port?: number) {
const app = await getApp();
const app = await getApp(host, port);
// getting port from env
const sHost = host || process.env.CORTEX_JS_HOST || defaultCortexJsHost;
const sPort = port || process.env.CORTEX_JS_PORT || defaultCortexJsPort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export class CortexCommand extends CommandRunner {

this.host = options?.address || configApiServerHost || defaultCortexJsHost;
this.port = options?.port || configApiServerPort || defaultCortexJsPort;
if(this.host === 'localhost') {
this.host = '127.0.0.1';
}
this.enginePort =
Number(options?.enginePort) ||
configCortexCppPort ||
Expand Down Expand Up @@ -134,7 +137,7 @@ export class CortexCommand extends CommandRunner {
await fileManagerService.getConfig(dataFolderPath);
}
if (attach) {
const app = await getApp();
const app = await getApp(this.host, this.port);
await app.listen(this.port, this.host);
} else {
await this.cortexUseCases.startServerDetached(this.host, this.port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class FileManagerService {
private benchmarkFoldername = 'benchmark';
private cortexEnginesFolderName = 'engines';
private cortexTelemetryFolderName = 'telemetry';
private configProfile = 'default';
private configProfile = process.env.CORTEX_PROFILE || 'default';

/**
* Get cortex configs
Expand Down Expand Up @@ -353,14 +353,17 @@ export class FileManagerService {
config = configs?.[this.configProfile] ?? config;
} catch {}
return {
host: config.apiServerHost ?? 'localhost',
host: config.apiServerHost ?? '127.0.0.1',
port: config.apiServerPort ?? 1337,
};
}

public setConfigProfile(profile: string) {
this.configProfile = profile;
}
public getConfigProfile() {
return this.configProfile;
}
public profileConfigExists(profile: string): boolean {
const homeDir = os.homedir();
const configPath = join(homeDir, this.configFile);
Expand Down
1 change: 1 addition & 0 deletions cortex-js/src/usecases/cortex/cortex.usecases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class CortexUsecases implements BeforeApplicationShutdown {
env: {
CORTEX_JS_HOST: host,
CORTEX_JS_PORT: port.toString(),
CORTEX_PROFILE: fileManagerService.getConfigProfile(),
},
});
server.disconnect(); // closes the IPC channel
Expand Down
Loading