diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/config.go | 4 | ||||
| -rw-r--r-- | backend/main.go | 36 |
2 files changed, 23 insertions, 17 deletions
diff --git a/backend/config.go b/backend/config.go index c083542..99a6d54 100644 --- a/backend/config.go +++ b/backend/config.go @@ -11,6 +11,7 @@ type Config struct { dbUser string dbPassword string dbName string + isLocal bool } func NewConfigFromEnv() (*Config, error) { @@ -34,11 +35,14 @@ func NewConfigFromEnv() (*Config, error) { if !exists { return nil, fmt.Errorf("ALBATROSS_DB_NAME not set") } + isLocalStr, exists := os.LookupEnv("ALBATROSS_IS_LOCAL") + isLocal := exists && isLocalStr == "1" return &Config{ dbHost: dbHost, dbPort: dbPort, dbUser: dbUser, dbPassword: dbPassword, dbName: dbName, + isLocal: isLocal, }, nil } diff --git a/backend/main.go b/backend/main.go index 1b69bb0..7ca66ac 100644 --- a/backend/main.go +++ b/backend/main.go @@ -87,23 +87,25 @@ func main() { adminGroup := e.Group("/iosdc-japan/2024/code-battle/admin") adminHandler.RegisterHandlers(adminGroup) - // For local dev: This is never used in production because the reverse - // proxy directly handles /files. - filesGroup := e.Group("/iosdc-japan/2024/code-battle/files") - filesGroup.Use(middleware.StaticWithConfig(middleware.StaticConfig{ - Root: "/", - Filesystem: http.Dir("/data/files"), - IgnoreBase: true, - })) - - // For local dev: This is never used in production because the reverse - // proxy sends these paths to the app server. - e.GET("/iosdc-japan/2024/code-battle/*", func(c echo.Context) error { - return c.Redirect(http.StatusPermanentRedirect, "http://localhost:5173"+c.Request().URL.Path) - }) - e.POST("/iosdc-japan/2024/code-battle/*", func(c echo.Context) error { - return c.Redirect(http.StatusPermanentRedirect, "http://localhost:5173"+c.Request().URL.Path) - }) + if config.isLocal { + // For local dev: This is never used in production because the reverse + // proxy directly handles /files. + filesGroup := e.Group("/iosdc-japan/2024/code-battle/files") + filesGroup.Use(middleware.StaticWithConfig(middleware.StaticConfig{ + Root: "/", + Filesystem: http.Dir("/data/files"), + IgnoreBase: true, + })) + + // For local dev: This is never used in production because the reverse + // proxy sends these paths to the app server. + e.GET("/iosdc-japan/2024/code-battle/*", func(c echo.Context) error { + return c.Redirect(http.StatusPermanentRedirect, "http://localhost:5173"+c.Request().URL.Path) + }) + e.POST("/iosdc-japan/2024/code-battle/*", func(c echo.Context) error { + return c.Redirect(http.StatusPermanentRedirect, "http://localhost:5173"+c.Request().URL.Path) + }) + } go gameHubs.Run() |
