From d704b15096a8236c43b2df903268e1f68dd61af4 Mon Sep 17 00:00:00 2001 From: Arthur de Moulins Date: Wed, 4 Dec 2024 17:53:10 +0100 Subject: [PATCH] add `--studio-host` option on dev server --- packages/novu/README.MD | 19 ++++++++++--------- packages/novu/src/commands/dev/types.ts | 1 + packages/novu/src/dev-server/http-server.ts | 9 ++++----- packages/novu/src/index.ts | 1 + 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/novu/README.MD b/packages/novu/README.MD index e6a8fc5ebb6..def70f6e015 100644 --- a/packages/novu/README.MD +++ b/packages/novu/README.MD @@ -34,15 +34,16 @@ npx novu@latest dev ## 🔥 Flags -| flag | long form usage example | description | default value | -| ---- | ----------------------- | ----------------------------- | --------------------------- | -| -p | --port | Bridge application port | 4000 | -| -r | --route | Bridge application route | /api/novu | -| -o | --origin | Bridge application origin | http://localhost | -| -d | --dashboard-url | Novu Cloud dashboard URL | https://dashboard.novu.co | -| -sp | --studio-port | Local Studio server port | 2022 | -| -t | --tunnel | Self hosted tunnel url | null | -| -H | --headless | Run bridge in headless mode | false | +| flag | long form usage example | description | default value | +|------|-------------------------|-----------------------------| --------------------------- | +| -p | --port | Bridge application port | 4000 | +| -r | --route | Bridge application route | /api/novu | +| -o | --origin | Bridge application origin | http://localhost | +| -d | --dashboard-url | Novu Cloud dashboard URL | https://dashboard.novu.co | +| -sp | --studio-port | Local Studio server port | 2022 | +| -sh | --studio-host | Local Studio server host | localhost | +| -t | --tunnel | Self hosted tunnel url | null | +| -H | --headless | Run bridge in headless mode | false | Example: If bridge application is running on port `3002` and Novu account is in `EU` region. diff --git a/packages/novu/src/commands/dev/types.ts b/packages/novu/src/commands/dev/types.ts index e0d23ef09f9..21cf37d3055 100644 --- a/packages/novu/src/commands/dev/types.ts +++ b/packages/novu/src/commands/dev/types.ts @@ -5,6 +5,7 @@ export type DevCommandOptions = { origin: string; region: `${CloudRegionEnum}`; studioPort: string; + studioHost: string; dashboardUrl: string; route: string; tunnel: string; diff --git a/packages/novu/src/dev-server/http-server.ts b/packages/novu/src/dev-server/http-server.ts index d81b78f539f..7e02220ff8c 100644 --- a/packages/novu/src/dev-server/http-server.ts +++ b/packages/novu/src/dev-server/http-server.ts @@ -2,14 +2,13 @@ import http from 'node:http'; import { AddressInfo } from 'net'; import getPort from 'get-port'; -import { SERVER_HOST } from '../constants'; import { DevCommandOptions } from '../commands'; export const WELL_KNOWN_ROUTE = '/.well-known/novu'; export const STUDIO_PATH = '/studio'; export type DevServerOptions = { tunnelOrigin: string; anonymousId?: string } & Partial< - Pick + Pick >; export class DevServer { @@ -19,7 +18,7 @@ export class DevServer { constructor(private options: DevServerOptions) {} public async listen(): Promise { - const port = await getPort({ host: SERVER_HOST, port: Number(this.options.studioPort) }); + const port = await getPort({ host: this.options.studioHost, port: Number(this.options.studioPort) }); this.server = http.createServer(); this.server.on('request', async (req, res) => { try { @@ -41,7 +40,7 @@ export class DevServer { }); await new Promise((resolve) => { - this.server.listen(port, SERVER_HOST, () => { + this.server.listen(port, this.options.studioHost, () => { resolve(); }); }); @@ -50,7 +49,7 @@ export class DevServer { public getAddress() { const response = this.server.address() as AddressInfo; - return `http://${SERVER_HOST}:${response.port}`; + return `http://${this.options.studioHost}:${response.port}`; } public getStudioAddress() { diff --git a/packages/novu/src/index.ts b/packages/novu/src/index.ts index 6ce6615c845..787cd692c4e 100644 --- a/packages/novu/src/index.ts +++ b/packages/novu/src/index.ts @@ -71,6 +71,7 @@ program .option('-o, --origin ', 'The Bridge endpoint origin') .option('-d, --dashboard-url ', 'The Novu Cloud Dashboard URL', 'https://dashboard.novu.co') .option('-sp, --studio-port ', 'The Local Studio server port', '2022') + .option('-sh, --studio-host ', 'The Local Studio server host', 'localhost') .option('-t, --tunnel ', 'Self hosted tunnel. e.g. https://my-tunnel.ngrok.app') .option('-H, --headless', 'Run the Bridge in headless mode without opening the browser', false) .action(async (options: DevCommandOptions) => {