Skip to content

Commit d64eb48

Browse files
committed
feat: 支持配置前置代理
1 parent a8f6b63 commit d64eb48

File tree

21 files changed

+409
-26
lines changed

21 files changed

+409
-26
lines changed

backend/cmd/server/wire_gen.go

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/config/config.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/spf13/viper"
1010

11+
"github.com/chaitin/MonkeyCode/backend/domain"
1112
"github.com/chaitin/MonkeyCode/backend/pkg/logger"
1213
)
1314

@@ -77,14 +78,26 @@ type Config struct {
7778
} `mapstructure:"data_report"`
7879
}
7980

80-
func (c *Config) GetBaseURL(req *http.Request) string {
81+
func (c *Config) GetBaseURL(req *http.Request, settings *domain.Setting) string {
8182
scheme := "http"
8283
if req.TLS != nil {
8384
scheme = "https"
8485
}
8586
if proto := req.Header.Get("X-Forwarded-Proto"); proto != "" {
8687
scheme = proto
8788
}
89+
90+
if settings != nil && settings.BaseURL != "" {
91+
baseurl := settings.BaseURL
92+
if !strings.HasPrefix(baseurl, "http") {
93+
baseurl = fmt.Sprintf("%s://%s", scheme, baseurl)
94+
}
95+
return strings.TrimSuffix(baseurl, "/")
96+
}
97+
98+
if port := req.Header.Get("X-Forwarded-Port"); port != "" && port != "80" && port != "443" {
99+
c.Server.Port = port
100+
}
88101
baseurl := fmt.Sprintf("%s://%s", scheme, req.Host)
89102
if c.Server.Port != "" {
90103
baseurl = fmt.Sprintf("%s:%s", baseurl, c.Server.Port)

backend/db/migrate/schema.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/db/mutation.go

Lines changed: 74 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/db/runtime/runtime.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/db/setting.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/db/setting/setting.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)