Skip to content

Commit d844fbc

Browse files
authored
Fix origins present in config.ini being ignored (#893)
* fix origins specified in the config.ini being ignored, and typo * add again wildcard support in origin config option
1 parent 3be373a commit d844fbc

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

main.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"runtime"
3030
"runtime/debug"
3131
"strconv"
32+
"strings"
3233
"time"
3334

3435
cert "github.com/arduino/arduino-create-agent/certificates"
@@ -372,10 +373,16 @@ func loop() {
372373
extraOrigins = append(extraOrigins, "https://127.0.0.1:"+port)
373374
}
374375

375-
allowOrigings := []string{*origins}
376-
allowOrigings = append(allowOrigings, extraOrigins...)
376+
allowOrigins := strings.Split(*origins, ",")
377+
// We need to trim possible spaces from the origins, otherwise the CORS middleware
378+
// validation might not work as expected
379+
for i := range allowOrigins {
380+
allowOrigins[i] = strings.TrimSpace(allowOrigins[i])
381+
}
382+
allowOrigins = append(allowOrigins, extraOrigins...)
377383
r.Use(cors.New(cors.Config{
378-
AllowOrigins: allowOrigings,
384+
AllowWildcard: true,
385+
AllowOrigins: allowOrigins,
379386
AllowMethods: []string{"PUT", "GET", "POST", "DELETE"},
380387
AllowHeaders: []string{"Origin", "Authorization", "Content-Type"},
381388
ExposeHeaders: []string{},

0 commit comments

Comments
 (0)