mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 19:41:09 +02:00
🐛 fix(cors): handle both string and array corsOriginsEnv
The mana-core-auth configuration.ts was already splitting CORS_ORIGINS into an array, but createCorsConfig expected a string and called .split() on it, causing "corsOriginsEnv.split is not a function" TypeError. Now handles both string and array inputs gracefully. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
05ad5f1ed8
commit
70c9196b40
1 changed files with 17 additions and 11 deletions
|
|
@ -2,10 +2,11 @@ import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-option
|
|||
|
||||
export interface CorsConfigOptions {
|
||||
/**
|
||||
* Comma-separated list of allowed origins from environment variable.
|
||||
* Allowed origins from environment variable.
|
||||
* Can be a comma-separated string or an array of origins.
|
||||
* If not provided, uses development defaults.
|
||||
*/
|
||||
corsOriginsEnv?: string;
|
||||
corsOriginsEnv?: string | string[];
|
||||
|
||||
/**
|
||||
* Default origins for development. Only used if corsOriginsEnv is not provided.
|
||||
|
|
@ -220,12 +221,14 @@ export function createCorsConfig(options: CorsConfigOptions = {}): CorsOptions {
|
|||
includeAllManaApps = false,
|
||||
} = options;
|
||||
|
||||
// Parse CORS_ORIGINS from environment
|
||||
// Parse CORS_ORIGINS from environment (handles both string and array)
|
||||
const envOrigins = corsOriginsEnv
|
||||
? corsOriginsEnv
|
||||
.split(',')
|
||||
.map((origin) => origin.trim())
|
||||
.filter(Boolean)
|
||||
? Array.isArray(corsOriginsEnv)
|
||||
? corsOriginsEnv.map((origin) => origin.trim()).filter(Boolean)
|
||||
: corsOriginsEnv
|
||||
.split(',')
|
||||
.map((origin) => origin.trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
|
||||
// Combine all origins
|
||||
|
|
@ -263,11 +266,14 @@ export function createCorsConfigWithCallback(options: CorsConfigOptions = {}): C
|
|||
includeAllManaApps = false,
|
||||
} = options;
|
||||
|
||||
// Parse CORS_ORIGINS from environment (handles both string and array)
|
||||
const envOrigins = corsOriginsEnv
|
||||
? corsOriginsEnv
|
||||
.split(',')
|
||||
.map((origin) => origin.trim())
|
||||
.filter(Boolean)
|
||||
? Array.isArray(corsOriginsEnv)
|
||||
? corsOriginsEnv.map((origin) => origin.trim()).filter(Boolean)
|
||||
: corsOriginsEnv
|
||||
.split(',')
|
||||
.map((origin) => origin.trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
|
||||
const allOrigins = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue