Skip to content

Commit 5911622

Browse files
authored
docs: add docs for the HTTP server (#1271)
* docs: add docs for the HTTP server * docs: minor polish * docs: add more explanation to the internal API.
1 parent b0e41f3 commit 5911622

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

docs/docs/http_server.mdx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: HTTP Server
3+
description: Run the built-in HTTP server for CocoInsight and health check
4+
---
5+
6+
## Start the server
7+
8+
There are two ways to start the server:
9+
10+
### CLI
11+
12+
Use the `cocoindex server` command. See more options in the [CLI](./core/cli).
13+
14+
- Default bind address: **127.0.0.1:49344** (only exposed locally for safety)
15+
- Override if you need to expose to all IPs (example: `0.0.0.0:49344`)
16+
17+
```bash
18+
# Start on the default local address (127.0.0.1:49344)
19+
cocoindex server path/to/app.py
20+
21+
# Expose to all interfaces and allow CocoInsight
22+
cocoindex server path/to/app.py -a 0.0.0.0:49344 -ci
23+
24+
# Add a custom CORS origin or allow a local frontend port
25+
cocoindex server path/to/app.py \
26+
-c https://example.com \
27+
-cl 3000
28+
```
29+
30+
Flags of interest:
31+
32+
- `-a`, `--address <IP:PORT>`: Bind address (defaults to 127.0.0.1:49344)
33+
- `-ci`, `--cors-cocoindex`: Allow `https://cocoindex.io` (CocoInsight) to access the server
34+
- `-c`, `--cors-origin <ORIGINS>`: Comma-separated list of allowed origins
35+
- `-cl`, `--cors-local <PORT>`: Allow `http://localhost:<PORT>`
36+
- `-L`, `--live-update`: Enable live updates while the server is running
37+
38+
### Python API
39+
40+
You can also start the server programmatically via the API.
41+
42+
```python
43+
from cocoindex import start_server, settings
44+
45+
server_settings = settings.ServerSettings(
46+
# Default: "127.0.0.1:49344" — local only for safety
47+
address="127.0.0.1:49344",
48+
# Allow CocoInsight front-end
49+
cors_origins=["https://cocoindex.io"],
50+
)
51+
52+
start_server(server_settings)
53+
```
54+
55+
To expose to all IPs:
56+
57+
```python
58+
server_settings = settings.ServerSettings(
59+
address="0.0.0.0:49344",
60+
)
61+
start_server(server_settings)
62+
```
63+
64+
## What the server provides today
65+
66+
- **CocoInsight access**: Enable with CLI `-ci`, or by API set `ServerSettings.cors_origins` to `"https://cocoindex.io"`. Then open `https://cocoindex.io/cocoinsight` and point it to your server address.
67+
It'll talk to CocoIndex internal REST APIs exposed through `/cocoindex/api`.
68+
The internal API is mainly designed for CocoInsight to use today, is subject to change and not considered as stable.
69+
70+
- **Live updates from the CLI**: When running with `-L`, the server performs live updates while it’s up.
71+
It's doing same thing as `cocoindex update -L` while the HTTP server is running.
72+
73+
- **Health check**: `GET /healthz` responds with `application/json`:
74+
75+
- `status`: always `"ok"` when healthy
76+
- `version`: the build-time package version (e.g., `"0.3.5"`)
77+
78+
Example response:
79+
80+
```json
81+
{"status":"ok","version":"0.3.5"}
82+
```

docs/sidebars.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ const sidebars: SidebarsConfig = {
8383
'ai/llm',
8484
],
8585
},
86+
{
87+
type: 'doc',
88+
id: 'http_server',
89+
label: 'HTTP Server',
90+
},
8691
{
8792
type: 'doc',
8893
id: 'query',

0 commit comments

Comments
 (0)