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

Commit 4dfdbb8

Browse files
committed
chore: add api serve stop subcommand - update -h to -a
1 parent d5aad63 commit 4dfdbb8

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

cortex-js/src/command.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command
3131
import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command';
3232
import { EventEmitterModule } from '@nestjs/event-emitter';
3333
import { DownloadManagerModule } from './download-manager/download-manager.module';
34+
import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command';
3435

3536
@Module({
3637
imports: [
@@ -78,6 +79,9 @@ import { DownloadManagerModule } from './download-manager/download-manager.modul
7879

7980
// Shortcuts
8081
RunCommand,
82+
83+
// Serve
84+
ServeStopCommand,
8185
],
8286
})
8387
export class CommandModule {}

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
import { spawn } from 'child_process';
22
import {
3-
CORTEX_JS_STOP_API_SERVER_URL,
43
defaultCortexJsHost,
54
defaultCortexJsPort,
65
} from '@/infrastructure/constants/cortex';
76
import { CommandRunner, SubCommand, Option } from 'nest-commander';
87
import { join } from 'path';
8+
import { ServeStopCommand } from './sub-commands/serve-stop.command';
99

1010
type ServeOptions = {
11-
host?: string;
11+
address?: string;
1212
port?: number;
1313
attach: boolean;
1414
};
1515

1616
@SubCommand({
1717
name: 'serve',
1818
description: 'Providing API endpoint for Cortex backend',
19+
subCommands: [ServeStopCommand],
1920
})
2021
export class ServeCommand extends CommandRunner {
2122
async run(_input: string[], options?: ServeOptions): Promise<void> {
22-
const host = options?.host || defaultCortexJsHost;
23+
const host = options?.address || defaultCortexJsHost;
2324
const port = options?.port || defaultCortexJsPort;
2425

25-
if (_input[0] === 'stop') {
26-
return this.stopServer().then(() => console.log('API server stopped'));
27-
} else {
28-
return this.startServer(host, port, options);
29-
}
30-
}
31-
32-
private async stopServer() {
33-
return fetch(CORTEX_JS_STOP_API_SERVER_URL(), {
34-
method: 'DELETE',
35-
}).catch(() => {});
26+
return this.startServer(host, port, options);
3627
}
3728

3829
private async startServer(
@@ -63,8 +54,8 @@ export class ServeCommand extends CommandRunner {
6354
}
6455

6556
@Option({
66-
flags: '-h, --host <host>',
67-
description: 'Host to serve the application',
57+
flags: '-a, --address <address>',
58+
description: 'Address to use',
6859
})
6960
parseHost(value: string) {
7061
return value;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { CORTEX_JS_STOP_API_SERVER_URL } from '@/infrastructure/constants/cortex';
2+
import { CommandRunner, SubCommand } from 'nest-commander';
3+
4+
@SubCommand({
5+
name: 'stop',
6+
description: 'Stop the API server',
7+
})
8+
export class ServeStopCommand extends CommandRunner {
9+
async run(): Promise<void> {
10+
return this.stopServer().then(() => console.log('API server stopped'));
11+
}
12+
13+
private async stopServer() {
14+
return fetch(CORTEX_JS_STOP_API_SERVER_URL(), {
15+
method: 'DELETE',
16+
}).catch(() => {});
17+
}
18+
}

0 commit comments

Comments
 (0)