Skip to content

Commit 2f840fd

Browse files
feat: configure gin.TrustedPlatform properly
1 parent 202c004 commit 2f840fd

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

cmd/ebuild/run/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (s *serverRunner) runAPI(cmd *cobra.Command, args []string) {
6363
s.opts.HTTPBindAddress,
6464
s.opts.HTTPBindPort,
6565
),
66+
s.opts,
6667
)
6768
if err != nil {
6869
fmt.Printf("failed to start API server: %s", err)

config/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type CloudbuildOpts struct {
7979
LogLevel LogLevel `mapstructure:"log-level"`
8080
HTTPBindAddress net.IP `mapstructure:"listen-ip"`
8181
HTTPBindPort uint16 `mapstructure:"port"`
82+
TrustedPlatform string `mapstructure:"platform"`
8283

8384
// Database options:
8485
DatabaseDSN string `mapstructure:"database-dsn"`

server/http.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/edgetx/cloudbuild/artifactory"
1111
"github.com/edgetx/cloudbuild/auth"
12+
"github.com/edgetx/cloudbuild/config"
1213
"github.com/edgetx/cloudbuild/processor"
1314
"github.com/edgetx/cloudbuild/targets"
1415
"github.com/gin-contrib/static"
@@ -226,14 +227,17 @@ func debugRoutes(method, path, _ string, _ int) {
226227
}).Debugf("endpoint")
227228
}
228229

229-
func (app *Application) Start(listen string) error {
230+
func (app *Application) Start(listen string, opts *config.CloudbuildOpts) error {
230231
gin.DebugPrintRouteFunc = debugRoutes
231232
router := gin.New()
232233
router.Use(ginlogrus.Logger(log.New()))
233234
router.Use(gin.Recovery())
234235

235-
// this should be a config parameter (in case behind CF)
236-
router.SetTrustedProxies(nil) //nolint:errcheck
236+
if opts.TrustedPlatform == "cloudflare" {
237+
router.TrustedPlatform = gin.PlatformCloudflare
238+
} else {
239+
router.SetTrustedProxies(nil) //nolint:errcheck
240+
}
237241

238242
// later this should server static content (dashboard app?)
239243
router.Use(static.ServeRoot("/", staticContentDir))

0 commit comments

Comments
 (0)