Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
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
2 changes: 2 additions & 0 deletions cortex-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"bin": {
"cortex": "./dist/src/command.js"
},
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"scripts": {
"dev": "nest dev",
"compile": "npx ncc build ./dist/src/command.js -o command",
Expand Down
37 changes: 37 additions & 0 deletions cortex-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
CORTEX_JS_STOP_API_SERVER_URL,
defaultCortexJsHost,
defaultCortexJsPort,
} from '@/infrastructure/constants/cortex';
import { getApp } from './app';
import chalk from 'chalk';

/**
* Start the API server
*/
export async function start(host?: string, port?: number) {
const app = await getApp();
// getting port from env
const sHost = host || process.env.CORTEX_JS_HOST || defaultCortexJsHost;
const sPort = port || process.env.CORTEX_JS_PORT || defaultCortexJsPort;

try {
await app.listen(sPort, sHost);
console.log(chalk.blue(`Started server at http://${sHost}:${sPort}`));
console.log(
chalk.blue(`API Playground available at http://${sHost}:${sPort}/api`),
);
} catch {
console.error(`Failed to start server. Is port ${port} in use?`);
}
}

/**
* Stop the API server
* @returns
*/
export async function stop() {
return fetch(CORTEX_JS_STOP_API_SERVER_URL(), {
method: 'DELETE',
}).catch(() => {});
}