Skip to content

Commit

Permalink
chore: add an entry to allow JS import (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan authored Jul 15, 2024
1 parent 69ba031 commit 8612d59
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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(() => {});
}

0 comments on commit 8612d59

Please sign in to comment.