-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1652 from janhq/j/add-docs-cors
docs: add cors docs
- Loading branch information
Showing
3 changed files
with
239 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
--- | ||
title: CORS | ||
description: Setting up CORS | ||
slug: "cors" | ||
--- | ||
|
||
import Tabs from "@theme/Tabs"; | ||
import TabItem from "@theme/TabItem"; | ||
|
||
:::warning | ||
🚧 Cortex.cpp is currently under development. Our documentation outlines the intended behavior of Cortex, which may not yet be fully implemented in the codebase. | ||
::: | ||
|
||
# CORS Configuration Guide | ||
|
||
This document describes how to configure Cross-Origin Resource Sharing (CORS) settings for the API server using both CLI commands and HTTP API endpoints. | ||
|
||
## Command Line Interface (CLI) | ||
|
||
### Basic Usage | ||
|
||
```bash | ||
cortex config [OPTIONS] [COMMAND] | ||
``` | ||
|
||
### Commands | ||
|
||
- `status`: Display all current configurations | ||
|
||
```bash | ||
cortex config status | ||
``` | ||
|
||
Example Output: | ||
|
||
```bash | ||
+-----------------+-------------------+ | ||
| Config name | Value | | ||
+-----------------+-------------------+ | ||
| allowed_origins | http://localhost | | ||
+-----------------+-------------------+ | ||
| allowed_origins | https://cortex.so | | ||
+-----------------+-------------------+ | ||
| cors | true | | ||
+-----------------+-------------------+ | ||
``` | ||
|
||
### Options | ||
|
||
| Option | Description | Example | | ||
| ----------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------- | | ||
| `-h, --help` | Print help message and exit | | ||
| `--cors [on/off]` | Toggle CORS functionality | cortex config --cors on | | ||
| `--allowed_origins [origins]` | Set allowed origins for CORS, comma separated without spaces | `cortex config --allowed_origins http://localhost,https://cortex.so` | | ||
|
||
### Examples | ||
|
||
1. Toggle CORS on: | ||
|
||
```bash | ||
cortex config --cors on | ||
``` | ||
|
||
2. Toggle CORS off: | ||
|
||
```bash | ||
cortex config --cors off | ||
``` | ||
|
||
3. Set allowed origins: | ||
|
||
```bash | ||
cortex config --allowed_origins http://localhost,https://cortex.so | ||
``` | ||
|
||
4. View current configuration: | ||
```bash | ||
cortex config status | ||
``` | ||
|
||
## CORS API Configuration | ||
|
||
This document describes the REST API endpoints available for managing CORS configurations. | ||
|
||
### Endpoints | ||
|
||
#### Get Current Configuration | ||
|
||
```http | ||
GET /v1/configs | ||
``` | ||
|
||
Retrieves the current CORS configuration settings. | ||
|
||
##### Response | ||
|
||
```json | ||
{ | ||
"allowed_origins": ["http://localhost:39281"], | ||
"cors": true | ||
} | ||
``` | ||
|
||
#### Update Configuration | ||
|
||
```http | ||
PATCH /v1/configs | ||
``` | ||
|
||
Updates CORS configuration settings. | ||
|
||
##### Request Headers | ||
|
||
``` | ||
Content-Type: application/json | ||
``` | ||
|
||
##### Request Body | ||
|
||
```json | ||
{ | ||
"cors": true, | ||
"allowed_origins": ["http://localhost:39281"] | ||
} | ||
``` | ||
|
||
##### Parameters | ||
|
||
| Field | Type | Description | | ||
| ----------------- | -------- | ---------------------------- | | ||
| `cors` | boolean | Enable or disable CORS | | ||
| `allowed_origins` | string[] | Array of allowed origin URLs | | ||
|
||
##### Response | ||
|
||
```json | ||
{ | ||
"config": { | ||
"allowed_origins": ["http://localhost:39281"], | ||
"cors": true | ||
}, | ||
"message": "Configuration updated successfully" | ||
} | ||
``` | ||
|
||
### Example cURL Commands | ||
|
||
#### Get Configuration | ||
|
||
```bash | ||
curl --location 'http://127.0.0.1:39281/v1/configs' | ||
``` | ||
|
||
#### Update Configuration | ||
|
||
```bash | ||
curl --location --request PATCH 'http://127.0.0.1:39281/v1/configs' \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{ | ||
"cors": true, | ||
"allowed_origins": [ | ||
"http://localhost:39281" | ||
] | ||
}' | ||
``` | ||
|
||
## Notes | ||
|
||
- Origins for CORS should be provided as comma-separated values without spaces | ||
- The `--allowed_origins` option only takes effect when CORS is enabled | ||
|
||
## Best Practices | ||
|
||
1. Always verify CORS status after toggling | ||
2. Double-check allowed origins to prevent security issues | ||
3. Use the `status` command to confirm changes have been applied correctly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
slug: /configurations | ||
title: Cortex configurations | ||
--- | ||
|
||
# Cortex Configurations | ||
|
||
Welcome to the Cortex configurations documentation. Here you will find detailed guides and references for configuring various aspects of Cortex, including: | ||
|
||
- **CORS**: Learn how to set up Cross-Origin Resource Sharing. | ||
|
||
Use the sidebar to navigate through the different configuration topics. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters