feat: allow to override ClientIP logic in gin
This commit is contained in:
parent
86220fed14
commit
3a6dbf8595
@ -2,6 +2,7 @@ WebServer:
|
||||
Address: ${WEB_SERVER_ADDRESS}
|
||||
Port: ${WEB_SERVER_PORT}
|
||||
PublicBase: ${WEB_SERVER_PUBLIC_BASE}
|
||||
TrustedPlatform: ${WEB_SERVER_TRUSTED_PLATFORM}
|
||||
JwtSigningKey: ${WEB_SERVER_JWT_SIGNING_KEY}
|
||||
JwtExpireHour: ${WEB_SERVER_JWT_EXPIRE_HOUR}
|
||||
OAuthDomain: ${WEB_SERVER_OAUTH_DOMAIN}
|
||||
|
@ -37,6 +37,7 @@ function check_env() {
|
||||
check_env "WEB_SERVER_ADDRESS" "0.0.0.0" true
|
||||
check_env "WEB_SERVER_PORT" 8000 false
|
||||
check_env "WEB_SERVER_PUBLIC_BASE" "http://127.0.0.1:8000" true
|
||||
check_env "WEB_SERVER_TRUSTED_PLATFORM" "" true
|
||||
check_env "WEB_SERVER_JWT_SIGNING_KEY" "$(head -n 10 /dev/urandom | md5sum | cut -c 1-32)" true
|
||||
check_env "WEB_SERVER_JWT_EXPIRE_HOUR" 12 false
|
||||
check_env "WEB_SERVER_OAUTH_DOMAIN" "" true
|
||||
|
@ -4,6 +4,7 @@ type ConfigWebServer struct {
|
||||
Address string `yaml:"Address"`
|
||||
Port int `yaml:"Port"`
|
||||
PublicBase string `yaml:"PublicBase"`
|
||||
TrustedPlatform string `yaml:"TrustedPlatform"`
|
||||
JwtSigningKey string `yaml:"JwtSigningKey"`
|
||||
JwtExpireHour int `yaml:"JwtExpireHour"`
|
||||
OAuthDomain string `yaml:"OAuthDomain"`
|
||||
|
@ -64,15 +64,20 @@ func (s *service) initRouters(conf *model.Config, injector *do.Injector) *gin.En
|
||||
gin.SetMode(utils.If[string](conf.Development, gin.DebugMode, gin.ReleaseMode))
|
||||
|
||||
r := gin.New()
|
||||
r.MaxMultipartMemory = 8 << 20 // 8MB
|
||||
|
||||
// +--------------+
|
||||
// |Configurations|
|
||||
// +--------------+
|
||||
|
||||
if conf.WebServer.TrustedPlatform != "" {
|
||||
// Extract Origin IP
|
||||
r.TrustedPlatform = conf.WebServer.TrustedPlatform
|
||||
}
|
||||
|
||||
// +-----------+
|
||||
// |Middlewares|
|
||||
// +-----------+
|
||||
|
||||
// static files - must before sentry
|
||||
r.Use(static.Serve("/", static.LocalFile("./resource/frontend", true)))
|
||||
|
||||
// Sentry middleware
|
||||
r.Use(sentrygin.New(sentrygin.Options{Repanic: true}))
|
||||
|
||||
@ -141,6 +146,9 @@ func (s *service) initRouters(conf *model.Config, injector *do.Injector) *gin.En
|
||||
r.GET(s.oauth.GetCallbackPath(), s.oauth.CallbackHandler())
|
||||
}
|
||||
|
||||
// static files
|
||||
r.Use(static.Serve("/", static.LocalFile("./resource/frontend", true)))
|
||||
|
||||
// fallback to frontend
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
c.File("./resource/frontend/index.html")
|
||||
|
@ -1 +0,0 @@
|
||||
package web
|
Loading…
Reference in New Issue
Block a user