Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6892823

Browse files
authored
Merge pull request menloresearch#1652 from janhq/j/add-docs-cors
docs: add cors docs
2 parents 2a8f187 + 7e1dd01 commit 6892823

File tree

3 files changed

+239
-16
lines changed

3 files changed

+239
-16
lines changed

docs/docs/configurations/cors.mdx

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
title: CORS
3+
description: Setting up CORS
4+
slug: "cors"
5+
---
6+
7+
import Tabs from "@theme/Tabs";
8+
import TabItem from "@theme/TabItem";
9+
10+
:::warning
11+
🚧 Cortex.cpp is currently under development. Our documentation outlines the intended behavior of Cortex, which may not yet be fully implemented in the codebase.
12+
:::
13+
14+
# CORS Configuration Guide
15+
16+
This document describes how to configure Cross-Origin Resource Sharing (CORS) settings for the API server using both CLI commands and HTTP API endpoints.
17+
18+
## Command Line Interface (CLI)
19+
20+
### Basic Usage
21+
22+
```bash
23+
cortex config [OPTIONS] [COMMAND]
24+
```
25+
26+
### Commands
27+
28+
- `status`: Display all current configurations
29+
30+
```bash
31+
cortex config status
32+
```
33+
34+
Example Output:
35+
36+
```bash
37+
+-----------------+-------------------+
38+
| Config name | Value |
39+
+-----------------+-------------------+
40+
| allowed_origins | http://localhost |
41+
+-----------------+-------------------+
42+
| allowed_origins | https://cortex.so |
43+
+-----------------+-------------------+
44+
| cors | true |
45+
+-----------------+-------------------+
46+
```
47+
48+
### Options
49+
50+
| Option | Description | Example |
51+
| ----------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------- |
52+
| `-h, --help` | Print help message and exit |
53+
| `--cors [on/off]` | Toggle CORS functionality | cortex config --cors on |
54+
| `--allowed_origins [origins]` | Set allowed origins for CORS, comma separated without spaces | `cortex config --allowed_origins http://localhost,https://cortex.so` |
55+
56+
### Examples
57+
58+
1. Toggle CORS on:
59+
60+
```bash
61+
cortex config --cors on
62+
```
63+
64+
2. Toggle CORS off:
65+
66+
```bash
67+
cortex config --cors off
68+
```
69+
70+
3. Set allowed origins:
71+
72+
```bash
73+
cortex config --allowed_origins http://localhost,https://cortex.so
74+
```
75+
76+
4. View current configuration:
77+
```bash
78+
cortex config status
79+
```
80+
81+
## CORS API Configuration
82+
83+
This document describes the REST API endpoints available for managing CORS configurations.
84+
85+
### Endpoints
86+
87+
#### Get Current Configuration
88+
89+
```http
90+
GET /v1/configs
91+
```
92+
93+
Retrieves the current CORS configuration settings.
94+
95+
##### Response
96+
97+
```json
98+
{
99+
"allowed_origins": ["http://localhost:39281"],
100+
"cors": true
101+
}
102+
```
103+
104+
#### Update Configuration
105+
106+
```http
107+
PATCH /v1/configs
108+
```
109+
110+
Updates CORS configuration settings.
111+
112+
##### Request Headers
113+
114+
```
115+
Content-Type: application/json
116+
```
117+
118+
##### Request Body
119+
120+
```json
121+
{
122+
"cors": true,
123+
"allowed_origins": ["http://localhost:39281"]
124+
}
125+
```
126+
127+
##### Parameters
128+
129+
| Field | Type | Description |
130+
| ----------------- | -------- | ---------------------------- |
131+
| `cors` | boolean | Enable or disable CORS |
132+
| `allowed_origins` | string[] | Array of allowed origin URLs |
133+
134+
##### Response
135+
136+
```json
137+
{
138+
"config": {
139+
"allowed_origins": ["http://localhost:39281"],
140+
"cors": true
141+
},
142+
"message": "Configuration updated successfully"
143+
}
144+
```
145+
146+
### Example cURL Commands
147+
148+
#### Get Configuration
149+
150+
```bash
151+
curl --location 'http://127.0.0.1:39281/v1/configs'
152+
```
153+
154+
#### Update Configuration
155+
156+
```bash
157+
curl --location --request PATCH 'http://127.0.0.1:39281/v1/configs' \
158+
--header 'Content-Type: application/json' \
159+
--data '{
160+
"cors": true,
161+
"allowed_origins": [
162+
"http://localhost:39281"
163+
]
164+
}'
165+
```
166+
167+
## Notes
168+
169+
- Origins for CORS should be provided as comma-separated values without spaces
170+
- The `--allowed_origins` option only takes effect when CORS is enabled
171+
172+
## Best Practices
173+
174+
1. Always verify CORS status after toggling
175+
2. Double-check allowed origins to prevent security issues
176+
3. Use the `status` command to confirm changes have been applied correctly

docs/docs/configurations/index.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
slug: /configurations
3+
title: Cortex configurations
4+
---
5+
6+
# Cortex Configurations
7+
8+
Welcome to the Cortex configurations documentation. Here you will find detailed guides and references for configuring various aspects of Cortex, including:
9+
10+
- **CORS**: Learn how to set up Cross-Origin Resource Sharing.
11+
12+
Use the sidebar to navigate through the different configuration topics.

docs/sidebars.ts

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const sidebars: SidebarsConfig = {
3636
label: "Installation",
3737
link: {
3838
type: "doc",
39-
id: "installation"
39+
id: "installation",
4040
},
4141
collapsed: true,
4242
items: [
@@ -74,11 +74,28 @@ const sidebars: SidebarsConfig = {
7474
},
7575
collapsed: true,
7676
items: [
77-
{ type: "doc", id: "architecture/data-folder", label: "Cortex Data Folder" },
77+
{
78+
type: "doc",
79+
id: "architecture/data-folder",
80+
label: "Cortex Data Folder",
81+
},
7882
{ type: "doc", id: "architecture/cortex-db", label: "cortex.db" },
7983
{ type: "doc", id: "architecture/cortexrc", label: ".cortexrc" },
8084
{ type: "doc", id: "architecture/updater", label: "Updater" },
81-
]
85+
],
86+
},
87+
{
88+
type: "category",
89+
label: "Configurations",
90+
link: { type: "doc", id: "configurations/index" },
91+
collapsed: true,
92+
items: [
93+
{
94+
type: "doc",
95+
id: "configurations/cors",
96+
label: "CORS",
97+
},
98+
],
8299
},
83100
{
84101
type: "html",
@@ -99,11 +116,19 @@ const sidebars: SidebarsConfig = {
99116
{
100117
type: "category",
101118
label: "Running Models",
102-
link: { type: "doc", id: "capabilities/models/index"},
119+
link: { type: "doc", id: "capabilities/models/index" },
103120
collapsed: true,
104121
items: [
105-
{ type: "doc", id: "capabilities/models/model-yaml", label: "model.yaml" },
106-
{ type: "doc", id: "capabilities/models/presets", label: "Model Presets" },
122+
{
123+
type: "doc",
124+
id: "capabilities/models/model-yaml",
125+
label: "model.yaml",
126+
},
127+
{
128+
type: "doc",
129+
id: "capabilities/models/presets",
130+
label: "Model Presets",
131+
},
107132
],
108133
},
109134
{
@@ -115,19 +140,25 @@ const sidebars: SidebarsConfig = {
115140
{ type: "doc", id: "engines/llamacpp", label: "llama.cpp" },
116141
// { type: "doc", id: "engines/tensorrt-llm", label: "TensorRT-LLM" },
117142
// { type: "doc", id: "engines/onnx", label: "ONNX" },
118-
{ type: "doc", id: "engines/engine-extension", label: "Building Engine Extensions" },
119-
143+
{
144+
type: "doc",
145+
id: "engines/engine-extension",
146+
label: "Building Engine Extensions",
147+
},
120148
],
121149
},
122150
{
123151
type: "category",
124152
label: "Hardware Awareness",
125153
link: { type: "doc", id: "capabilities/hardware/index" },
126154
collapsed: true,
127-
items: [
128-
],
155+
items: [],
156+
},
157+
{
158+
type: "doc",
159+
id: "capabilities/text-generation",
160+
label: "Text Generation",
129161
},
130-
{ type: "doc", id: "capabilities/text-generation", label: "Text Generation" },
131162
// { type: "doc", id: "capabilities/image-generation", label: "Image Generation" },
132163
// { type: "doc", id: "capabilities/vision", label: "Vision" },
133164
// { type: "doc", id: "capabilities/audio-generation", label: "Audio Generation" },
@@ -141,14 +172,18 @@ const sidebars: SidebarsConfig = {
141172
value: "GUIDES",
142173
className: "sidebar-divider",
143174
},
144-
{ type: "doc", id: "guides/function-calling", label: "Function Calling"},
145-
{ type: "doc", id: "guides/structured-outputs", label: "Structured Outputs"},
175+
{ type: "doc", id: "guides/function-calling", label: "Function Calling" },
176+
{
177+
type: "doc",
178+
id: "guides/structured-outputs",
179+
label: "Structured Outputs",
180+
},
146181
{
147182
type: "html",
148183
value: "ASSISTANTS",
149184
className: "sidebar-divider",
150185
},
151-
{ type: "doc", id: "assistants/index", label: "Assistants"},
186+
{ type: "doc", id: "assistants/index", label: "Assistants" },
152187
{
153188
type: "category",
154189
label: "Tools",
@@ -173,9 +208,9 @@ const sidebars: SidebarsConfig = {
173208
{ type: "doc", id: "cli/models/index", label: "cortex models" },
174209
{ type: "doc", id: "cli/engines/index", label: "cortex engines" },
175210
{ type: "doc", id: "cli/ps", label: "cortex ps" },
176-
{ type: "doc", id: "cli/update", label: "cortex update" },
211+
{ type: "doc", id: "cli/update", label: "cortex update" },
177212
{ type: "doc", id: "cli/stop", label: "cortex stop" },
178-
]
213+
],
179214
};
180215

181216
export default sidebars;

0 commit comments

Comments
 (0)