Skip to content

Commit f609587

Browse files
committed
fix origins specified in the config.ini being ignored, and typo
1 parent 3be373a commit f609587

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

main.go

Lines changed: 9 additions & 3 deletions
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,15 @@ 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+
AllowOrigins: allowOrigins,
379385
AllowMethods: []string{"PUT", "GET", "POST", "DELETE"},
380386
AllowHeaders: []string{"Origin", "Authorization", "Content-Type"},
381387
ExposeHeaders: []string{},

0 commit comments

Comments
 (0)