Skip to content

Commit

Permalink
use gin-contrib/cors and enable private network
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Dec 14, 2023
1 parent 41e6372 commit 134fcbd
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ import (
"runtime"
"runtime/debug"
"strconv"
"strings"
"time"

cors "github.com/andela/gin-cors"
cert "github.com/arduino/arduino-create-agent/certificates"
"github.com/arduino/arduino-create-agent/config"
"github.com/arduino/arduino-create-agent/globals"
Expand All @@ -42,6 +40,7 @@ import (
"github.com/arduino/arduino-create-agent/updater"
v2 "github.com/arduino/arduino-create-agent/v2"
paths "github.com/arduino/go-paths-helper"
cors "github.com/gin-contrib/cors"

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / test (./ - ubuntu-latest)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / test (./ - ubuntu-latest)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / check-deps

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / test (./ - windows-latest)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / test (./ - windows-latest)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / check-cache

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / test (./ - macos-latest)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / test (./ - macos-latest)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, -amd64)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, -amd64)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / check-errors (./)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / check-errors (./)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / check-outdated (./)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / build (macos-12, -amd64)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / build (macos-12, -amd64)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / check-style (./)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

no required module provides package github.com/gin-contrib/cors; to add it:

Check failure on line 43 in main.go

View workflow job for this annotation

GitHub Actions / check-formatting (./)

no required module provides package github.com/gin-contrib/cors; to add it:
"github.com/gin-gonic/gin"
"github.com/go-ini/ini"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -373,14 +372,16 @@ func loop() {
extraOrigins = append(extraOrigins, "https://127.0.0.1:"+port)
}

r.Use(cors.Middleware(cors.Config{
Origins: *origins + ", " + strings.Join(extraOrigins, ", "),
Methods: "GET, PUT, POST, DELETE",
RequestHeaders: "Origin, Authorization, Content-Type",
ExposedHeaders: "",
MaxAge: 50 * time.Second,
Credentials: true,
ValidateHeaders: false,
allowOrigings := []string{*origins}
allowOrigings = append(allowOrigings, extraOrigins...)
r.Use(cors.New(cors.Config{
AllowOrigins: allowOrigings,
AllowMethods: []string{"PUT", "GET", "POST", "DELETE"},
AllowHeaders: []string{"Origin", "Authorization", "Content-Type"},
ExposeHeaders: []string{},
AllowCredentials: true,
MaxAge: 50 * time.Second,
AllowPrivateNetwork: true,
}))

r.LoadHTMLFiles("templates/nofirefox.html")
Expand Down

0 comments on commit 134fcbd

Please sign in to comment.