Skip to content

Commit

Permalink
fix: handle cases where corsAllowedOrigins is a string or an array
Browse files Browse the repository at this point in the history
  • Loading branch information
seansica committed Dec 30, 2024
1 parent 5806f6c commit fea9a62
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ function validateDomains(value) {
return; // '*' allows all origins; 'disable' explicitly disables CORS.
}

const origins = value.split(',').map(origin => origin.trim());
// Normalize value to an array of origins
const origins = Array.isArray(value)
? value

Check failure on line 101 in app/config/config.js

View workflow job for this annotation

GitHub Actions / static-checks

'?' should be placed at the end of the line
: value.split(',').map(origin => origin.trim());

Check failure on line 102 in app/config/config.js

View workflow job for this annotation

GitHub Actions / static-checks

':' should be placed at the end of the line

// Regex to validate FQDNs
const fqdnRegex = /^(?!:\/\/)([a-zA-Z0-9-_]+\.)+[a-zA-Z]{2,}$/;
Expand All @@ -111,7 +114,12 @@ function validateDomains(value) {
convict.addFormat({
name: 'domains',
validate: validateDomains,
coerce: value => value.split(',').map(origin => origin.trim()), // Normalize the input
coerce: value => {
if (Array.isArray(value)) {
return value.map(origin => origin.trim());
}
return value.split(',').map(origin => origin.trim()); // Normalize strings to arrays
},
});

function loadConfig() {
Expand Down

0 comments on commit fea9a62

Please sign in to comment.