Skip to content

Commit

Permalink
fix: simple cors requests enabled by default
Browse files Browse the repository at this point in the history
Fixes #1640.
  • Loading branch information
tkurki committed Oct 9, 2023
1 parent c9dc28a commit 53a12f0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ export function setupCors(
) {
const corsDebug = createDebug('signalk-server:cors')

const corsOptions: CorsOptions = {
credentials: true,
}
const corsOrigins = allowedCorsOrigins
? allowedCorsOrigins
.split(',')
.map((s: string) => s.trim().replace(/\/*$/, ''))
: []
corsDebug(`corsOrigins:${corsOrigins.toString()}`)
const corsOptions: CorsOptions = {
credentials: true,
origin: corsOrigins
// set origin only if corsOrigins are set so that
// we get the default cors module functionality
// for simple requests by default
if (corsOrigins.length) {
corsOptions.origin = corsOrigins
}

app.use(cors(corsOptions))
Expand Down

0 comments on commit 53a12f0

Please sign in to comment.