Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Opens a dashboard at `http://localhost:50234` showing live agent sessions, tool
| Flag | Description |
|------|-------------|
| `--port <number>` | Server port (default: 50234) |
| `--host <address>` | Bind address (default: localhost, use 0.0.0.0 for all interfaces) |
| `--no-browser` | Don't auto-open browser |
| `--project <path>` | Set project directory for plan tracking |
| `--help` | Show help |
Expand Down
13 changes: 13 additions & 0 deletions src/server/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DEFAULT_PORT } from "../shared/constants";

export interface CLIFlags {
port: number;
host: string;
noBrowser: boolean;
projectPath: string | null;
showHelp: boolean;
Expand All @@ -11,6 +12,7 @@ export function parseArgs(): CLIFlags {
const args = process.argv.slice(2);
const flags: CLIFlags = {
port: DEFAULT_PORT,
host: "localhost",
noBrowser: false,
projectPath: null,
showHelp: false,
Expand All @@ -29,6 +31,15 @@ export function parseArgs(): CLIFlags {
flags.port = parseInt(portValue);
i++;
}
} else if (arg === "--host") {
const hostValue = args[i + 1];
if (hostValue && /^[a-zA-Z0-9.\-:]+$/.test(hostValue)) {
flags.host = hostValue;
i++;
} else if (hostValue) {
console.warn(`[ocwatch] Invalid --host value ignored: ${hostValue}`);
i++;
}
} else if (arg === "--project") {
const projectPath = args[i + 1];
if (projectPath) {
Expand All @@ -49,13 +60,15 @@ Usage: ocwatch [options]

Options:
--port <number> Server port (default: 50234)
--host <address> Bind address (default: localhost, use 0.0.0.0 for all interfaces)
--no-browser Skip auto-opening browser
--project <path> Set default project filter
--help, -h Show this help message

Examples:
ocwatch
ocwatch --port 50999
ocwatch --host 0.0.0.0
ocwatch --no-browser
ocwatch --project /path/to/project
`);
Expand Down
21 changes: 16 additions & 5 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,18 @@ app.use("*", errorHandler);

app.use(
"/api/*",
cors({
origin: ["http://localhost:3000", "http://localhost:50234"],
credentials: true,
})
cors(
flags.host === "0.0.0.0"
? { origin: "*", credentials: false }
: {
origin: [
`http://localhost:3000`,
`http://localhost:${flags.port}`,
`http://${flags.host}:${flags.port}`,
],
credentials: true,
}
)
);

registerRoutes(app, { defaultProjectIdPromise });
Expand All @@ -103,10 +111,13 @@ app.notFound(async (c) => {
export { app };

const port = flags.port;
const url = `http://localhost:${port}`;
const hostname = flags.host;
const displayHost = hostname === "0.0.0.0" ? "localhost" : hostname;
const url = `http://${displayHost}:${port}`;

export default {
port,
hostname,
fetch: app.fetch,
};

Expand Down