feat(server): make CORS middleware configurable (#5123)

* feat(server): make CORS middleware configurable

Add detailed configuration options for CORS in config.yaml, including
origin, methods, headers, credentials, and max age. Update server
initialization to apply these settings dynamically instead of using
hardcoded values.

* fix(server): Fix default value and conditional logic issues in CORS configuration

- Changed the default value of `cors.maxAge` from `null` to `0`.
- Simplified the conditional check logic for `allowedHeaders`, removing duplicate checks for `corsAllowedHeaders` being `null`.

* fix(server): Fix CORS exposed headers configuration logic

- Removed redundant conditional checks. now directly validates array length when `corsExposedHeaders` has a truthy value

* Improve types + simplify checks

* fix(cors): align maxAge default with original behavior

* Adjust default array values

* Remove debug log

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
This commit is contained in:
awaae
2026-02-12 04:27:45 +09:00
committed by GitHub
parent 23ba3e5bb2
commit 10e08f0e3d
2 changed files with 44 additions and 5 deletions
+19
View File
@@ -71,6 +71,25 @@ basicAuthUser:
password: "password"
# Enables CORS proxy middleware
enableCorsProxy: false
# CORS settings (applied to all routes)
cors:
# Enable or disable CORS middleware
enabled: true
# Allowed origins. Use "null" to match the default browser file origin.
# You can set "*" to allow any origin, or a list of allowed origins.
origin:
- "null"
# Allowed methods
methods:
- "OPTIONS"
# Allowed request headers (optional)
allowedHeaders: []
# Exposed response headers (optional)
exposedHeaders: []
# Allow credentials (cookies, authorization headers)
credentials: false
# Preflight cache max age in seconds (optional)
maxAge: null
# -- REQUEST PROXY CONFIGURATION --
requestProxy:
# If a proxy is enabled, all outgoing HTTP/HTTPS requests will be routed through it.