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

Commit 8612d59

Browse files
authored
chore: add an entry to allow JS import (#878)
1 parent 69ba031 commit 8612d59

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

cortex-js/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"bin": {
99
"cortex": "./dist/src/command.js"
1010
},
11+
"main": "dist/src/index.js",
12+
"types": "dist/src/index.d.ts",
1113
"scripts": {
1214
"dev": "nest dev",
1315
"compile": "npx ncc build ./dist/src/command.js -o command",

cortex-js/src/index.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {
2+
CORTEX_JS_STOP_API_SERVER_URL,
3+
defaultCortexJsHost,
4+
defaultCortexJsPort,
5+
} from '@/infrastructure/constants/cortex';
6+
import { getApp } from './app';
7+
import chalk from 'chalk';
8+
9+
/**
10+
* Start the API server
11+
*/
12+
export async function start(host?: string, port?: number) {
13+
const app = await getApp();
14+
// getting port from env
15+
const sHost = host || process.env.CORTEX_JS_HOST || defaultCortexJsHost;
16+
const sPort = port || process.env.CORTEX_JS_PORT || defaultCortexJsPort;
17+
18+
try {
19+
await app.listen(sPort, sHost);
20+
console.log(chalk.blue(`Started server at http://${sHost}:${sPort}`));
21+
console.log(
22+
chalk.blue(`API Playground available at http://${sHost}:${sPort}/api`),
23+
);
24+
} catch {
25+
console.error(`Failed to start server. Is port ${port} in use?`);
26+
}
27+
}
28+
29+
/**
30+
* Stop the API server
31+
* @returns
32+
*/
33+
export async function stop() {
34+
return fetch(CORTEX_JS_STOP_API_SERVER_URL(), {
35+
method: 'DELETE',
36+
}).catch(() => {});
37+
}

0 commit comments

Comments
 (0)