Skip to content

Commit

Permalink
add --studio-host option on dev server
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Dec 4, 2024
1 parent 17eaa75 commit d704b15
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
19 changes: 10 additions & 9 deletions packages/novu/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ npx novu@latest dev

## 🔥 Flags

| flag | long form usage example | description | default value |
| ---- | ----------------------- | ----------------------------- | --------------------------- |
| -p | --port <port> | Bridge application port | 4000 |
| -r | --route <route> | Bridge application route | /api/novu |
| -o | --origin <origin> | Bridge application origin | http://localhost |
| -d | --dashboard-url <url> | Novu Cloud dashboard URL | https://dashboard.novu.co |
| -sp | --studio-port <port> | Local Studio server port | 2022 |
| -t | --tunnel <url> | Self hosted tunnel url | null |
| -H | --headless | Run bridge in headless mode | false |
| flag | long form usage example | description | default value |
|------|-------------------------|-----------------------------| --------------------------- |
| -p | --port <port> | Bridge application port | 4000 |
| -r | --route <route> | Bridge application route | /api/novu |
| -o | --origin <origin> | Bridge application origin | http://localhost |
| -d | --dashboard-url <url> | Novu Cloud dashboard URL | https://dashboard.novu.co |
| -sp | --studio-port <port> | Local Studio server port | 2022 |
| -sh | --studio-host <host> | Local Studio server host | localhost |
| -t | --tunnel <url> | 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.

Expand Down
1 change: 1 addition & 0 deletions packages/novu/src/commands/dev/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type DevCommandOptions = {
origin: string;
region: `${CloudRegionEnum}`;
studioPort: string;
studioHost: string;
dashboardUrl: string;
route: string;
tunnel: string;
Expand Down
9 changes: 4 additions & 5 deletions packages/novu/src/dev-server/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DevCommandOptions, 'origin' | 'port' | 'studioPort' | 'dashboardUrl' | 'route'>
Pick<DevCommandOptions, 'origin' | 'port' | 'studioPort' | 'studioHost' | 'dashboardUrl' | 'route'>
>;

export class DevServer {
Expand All @@ -19,7 +18,7 @@ export class DevServer {
constructor(private options: DevServerOptions) {}

public async listen(): Promise<void> {
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 {
Expand All @@ -41,7 +40,7 @@ export class DevServer {
});

await new Promise<void>((resolve) => {
this.server.listen(port, SERVER_HOST, () => {
this.server.listen(port, this.options.studioHost, () => {
resolve();
});
});
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions packages/novu/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ program
.option('-o, --origin <origin>', 'The Bridge endpoint origin')
.option('-d, --dashboard-url <url>', 'The Novu Cloud Dashboard URL', 'https://dashboard.novu.co')
.option('-sp, --studio-port <port>', 'The Local Studio server port', '2022')
.option('-sh, --studio-host <host>', 'The Local Studio server host', 'localhost')
.option('-t, --tunnel <url>', '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) => {
Expand Down

0 comments on commit d704b15

Please sign in to comment.