Skip to content

Commit 20c3d6d

Browse files
committed
fix: handle non-array Access-Control-Allow-Origin
Closes #2941
1 parent 2f188aa commit 20c3d6d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/daemon/config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,15 @@ function migrateConfig (ipfsd) {
183183
if (CURRENT_REVISION < 3) {
184184
const api = config.API || {}
185185
const httpHeaders = api.HTTPHeaders || {}
186-
const accessControlAllowOrigin = httpHeaders['Access-Control-Allow-Origin'] || []
186+
let accessControlAllowOrigin = httpHeaders['Access-Control-Allow-Origin'] || []
187+
188+
// Ensure accessControlAllowOrigin is an array
189+
if (!Array.isArray(accessControlAllowOrigin)) {
190+
// Convert string to array, or create empty array for other types
191+
accessControlAllowOrigin = typeof accessControlAllowOrigin === 'string'
192+
? [accessControlAllowOrigin]
193+
: []
194+
}
187195

188196
const addURL = url => {
189197
if (!accessControlAllowOrigin.includes(url)) {

0 commit comments

Comments
 (0)