Skip to main content
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​


cortex config [OPTIONS] [COMMAND]

Commands​

  • status: Display all current configurations


    cortex config status

    Example Output:


    +-----------------+-------------------+
    | Config name | Value |
    +-----------------+-------------------+
    | allowed_origins | http://localhost |
    +-----------------+-------------------+
    | allowed_origins | https://cortex.so |
    +-----------------+-------------------+
    | cors | true |
    +-----------------+-------------------+

Options​

OptionDescriptionExample
-h, --helpPrint help message and exit
--cors [on/off]Toggle CORS functionalitycortex config --cors on
--allowed_origins [origins]Set allowed origins for CORS, comma separated without spacescortex config --allowed_origins http://localhost,https://cortex.so

Examples​

  1. Toggle CORS on:


    cortex config --cors on

  2. Toggle CORS off:


    cortex config --cors off

  3. Set allowed origins:


    cortex config --allowed_origins http://localhost,https://cortex.so

  4. View current configuration:


    cortex config status

CORS API Configuration​

This document describes the REST API endpoints available for managing CORS configurations.

Endpoints​

Get Current Configuration​


GET /v1/configs

Retrieves the current CORS configuration settings.

Response​

{
"allowed_origins": ["http://localhost:39281"],
"cors": true
}

Update Configuration​


PATCH /v1/configs

Updates CORS configuration settings.

Request Headers​

Content-Type: application/json

Request Body​

{
"cors": true,
"allowed_origins": ["http://localhost:39281"]
}

Parameters​
FieldTypeDescription
corsbooleanEnable or disable CORS
allowed_originsstring[]Array of allowed origin URLs
Response​

{
"config": {
"allowed_origins": ["http://localhost:39281"],
"cors": true
},
"message": "Configuration updated successfully"
}

Example cURL Commands​

Get Configuration​


curl --location 'http://127.0.0.1:39281/v1/configs'

Update Configuration​


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