From 6e405347ad218a6eb2ac1e24a6074deb41f74407 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 18 Aug 2024 02:05:31 +0900 Subject: feat(backend): do not define local-only routes in prod env --- backend/main.go | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'backend/main.go') 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() -- cgit v1.2.3-70-g09d2