Skip to content

Commit 4994687

Browse files
opencode-agent[bot]triklozoid
authored andcommitted
docs: new configurable CORS option (anomalyco#6522)
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
1 parent 9ab72e0 commit 4994687

3 files changed

Lines changed: 28 additions & 17 deletions

File tree

packages/web/src/content/docs/cli.mdx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,12 @@ This starts an HTTP server that provides API access to opencode functionality wi
362362

363363
#### Flags
364364

365-
| Flag | Description |
366-
| ------------ | --------------------- |
367-
| `--port` | Port to listen on |
368-
| `--hostname` | Hostname to listen on |
369-
| `--mdns` | Enable mDNS discovery |
365+
| Flag | Description |
366+
| ------------ | ------------------------------------------ |
367+
| `--port` | Port to listen on |
368+
| `--hostname` | Hostname to listen on |
369+
| `--mdns` | Enable mDNS discovery |
370+
| `--cors` | Additional browser origin(s) to allow CORS |
370371

371372
---
372373

@@ -457,11 +458,12 @@ This starts an HTTP server and opens a web browser to access OpenCode through a
457458

458459
#### Flags
459460

460-
| Flag | Description |
461-
| ------------ | --------------------- |
462-
| `--port` | Port to listen on |
463-
| `--hostname` | Hostname to listen on |
464-
| `--mdns` | Enable mDNS discovery |
461+
| Flag | Description |
462+
| ------------ | ------------------------------------------ |
463+
| `--port` | Port to listen on |
464+
| `--hostname` | Hostname to listen on |
465+
| `--mdns` | Enable mDNS discovery |
466+
| `--cors` | Additional browser origin(s) to allow CORS |
465467

466468
---
467469

packages/web/src/content/docs/config.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ You can configure server settings for the `opencode serve` and `opencode web` co
132132
"server": {
133133
"port": 4096,
134134
"hostname": "0.0.0.0",
135-
"mdns": true
135+
"mdns": true,
136+
"cors": ["http://localhost:5173"]
136137
}
137138
}
138139
```
@@ -142,6 +143,7 @@ Available options:
142143
- `port` - Port to listen on.
143144
- `hostname` - Hostname to listen on. When `mdns` is enabled and no hostname is set, defaults to `0.0.0.0`.
144145
- `mdns` - Enable mDNS service discovery. This allows other devices on the network to discover your OpenCode server.
146+
- `cors` - Additional origins to allow for CORS when using the HTTP server from a browser-based client. Values must be full origins (scheme + host + optional port), eg `https://app.example.com`.
145147

146148
[Learn more about the server here](/docs/server).
147149

packages/web/src/content/docs/server.mdx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,23 @@ The `opencode serve` command runs a headless HTTP server that exposes an OpenAPI
1313
### Usage
1414

1515
```bash
16-
opencode serve [--port <number>] [--hostname <string>]
16+
opencode serve [--port <number>] [--hostname <string>] [--cors <origin>]
1717
```
1818

1919
#### Options
2020

21-
| Flag | Description | Default |
22-
| ------------ | --------------------- | ----------- |
23-
| `--port` | Port to listen on | `4096` |
24-
| `--hostname` | Hostname to listen on | `127.0.0.1` |
25-
| `--mdns` | Enable mDNS discovery | `false` |
21+
| Flag | Description | Default |
22+
| ------------ | ----------------------------------- | ----------- |
23+
| `--port` | Port to listen on | `4096` |
24+
| `--hostname` | Hostname to listen on | `127.0.0.1` |
25+
| `--mdns` | Enable mDNS discovery | `false` |
26+
| `--cors` | Additional browser origins to allow | `[]` |
27+
28+
`--cors` can be passed multiple times:
29+
30+
```bash
31+
opencode serve --cors http://localhost:5173 --cors https://app.example.com
32+
```
2633

2734
---
2835

0 commit comments

Comments
 (0)