Skip to content

Fix origins present in config.ini being ignored #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix origins specified in the config.ini being ignored, and typo
  • Loading branch information
umbynos committed Jan 24, 2024
commit f609587dbd8edd766499025b4a07ea4a74706137
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"runtime"
"runtime/debug"
"strconv"
"strings"
"time"

cert "github.com/arduino/arduino-create-agent/certificates"
Expand Down Expand Up @@ -372,10 +373,15 @@ func loop() {
extraOrigins = append(extraOrigins, "https://127.0.0.1:"+port)
}

allowOrigings := []string{*origins}
allowOrigings = append(allowOrigings, extraOrigins...)
allowOrigins := strings.Split(*origins, ",")
// We need to trim possible spaces from the origins, otherwise the CORS middleware
// validation might not work as expected
for i := range allowOrigins {
allowOrigins[i] = strings.TrimSpace(allowOrigins[i])
}
allowOrigins = append(allowOrigins, extraOrigins...)
r.Use(cors.New(cors.Config{
AllowOrigins: allowOrigings,
AllowOrigins: allowOrigins,
AllowMethods: []string{"PUT", "GET", "POST", "DELETE"},
AllowHeaders: []string{"Origin", "Authorization", "Content-Type"},
ExposeHeaders: []string{},
Expand Down