diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-18 02:05:31 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-18 02:05:37 +0900 |
| commit | 6e405347ad218a6eb2ac1e24a6074deb41f74407 (patch) | |
| tree | ff1480da8395ea677ace7cdf0c27f073bae5cbfb /backend | |
| parent | e2a7c44805a3dea3790c7f4e2f9787dd9ff66102 (diff) | |
| download | phperkaigi-2025-albatross-6e405347ad218a6eb2ac1e24a6074deb41f74407.tar.gz phperkaigi-2025-albatross-6e405347ad218a6eb2ac1e24a6074deb41f74407.tar.zst phperkaigi-2025-albatross-6e405347ad218a6eb2ac1e24a6074deb41f74407.zip | |
feat(backend): do not define local-only routes in prod env
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() |
