diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-19 01:21:28 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-19 02:09:49 +0900 |
| commit | 98974136648935143298c0e0a01714bb146909f1 (patch) | |
| tree | b42ad91ef652d4d86eb03d56cbda063caf0d0b78 /backend | |
| parent | 0ad3546aa69d2269e5d739e9b62bc956e95e7f6e (diff) | |
| download | phperkaigi-2025-albatross-98974136648935143298c0e0a01714bb146909f1.tar.gz phperkaigi-2025-albatross-98974136648935143298c0e0a01714bb146909f1.tar.zst phperkaigi-2025-albatross-98974136648935143298c0e0a01714bb146909f1.zip | |
refactor(backend): do not hard-code base path
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/admin/handler.go | 31 | ||||
| -rw-r--r-- | backend/admin/templates/base.html | 6 | ||||
| -rw-r--r-- | backend/admin/templates/dashboard.html | 6 | ||||
| -rw-r--r-- | backend/admin/templates/game_edit.html | 2 | ||||
| -rw-r--r-- | backend/admin/templates/games.html | 6 | ||||
| -rw-r--r-- | backend/admin/templates/user_edit.html | 2 | ||||
| -rw-r--r-- | backend/admin/templates/users.html | 6 |
7 files changed, 34 insertions, 25 deletions
diff --git a/backend/admin/handler.go b/backend/admin/handler.go index 1b60de5..17341d5 100644 --- a/backend/admin/handler.go +++ b/backend/admin/handler.go @@ -17,6 +17,10 @@ import ( "github.com/nsfisis/iosdc-japan-2024-albatross/backend/db" ) +const ( + basePath = "/iosdc-japan/2024/code-battle" +) + var jst = time.FixedZone("Asia/Tokyo", 9*60*60) type Handler struct { @@ -40,11 +44,11 @@ func newAdminMiddleware() echo.MiddlewareFunc { return func(c echo.Context) error { jwt, err := c.Cookie("albatross_token") if err != nil { - return c.Redirect(http.StatusSeeOther, "/iosdc-japan/2024/code-battle/login") + return c.Redirect(http.StatusSeeOther, basePath+"/login") } claims, err := auth.ParseJWT(jwt.Value) if err != nil { - return c.Redirect(http.StatusSeeOther, "/iosdc-japan/2024/code-battle/login") + return c.Redirect(http.StatusSeeOther, basePath+"/login") } if !claims.IsAdmin { return echo.NewHTTPError(http.StatusForbidden) @@ -69,7 +73,8 @@ func (h *Handler) RegisterHandlers(g *echo.Group) { func (h *Handler) getDashboard(c echo.Context) error { return c.Render(http.StatusOK, "dashboard", echo.Map{ - "Title": "Dashboard", + "BasePath": basePath, + "Title": "Dashboard", }) } @@ -90,8 +95,9 @@ func (h *Handler) getUsers(c echo.Context) error { } return c.Render(http.StatusOK, "users", echo.Map{ - "Title": "Users", - "Users": users, + "BasePath": basePath, + "Title": "Users", + "Users": users, }) } @@ -109,7 +115,8 @@ func (h *Handler) getUserEdit(c echo.Context) error { } return c.Render(http.StatusOK, "user_edit", echo.Map{ - "Title": "User Edit", + "BasePath": basePath, + "Title": "User Edit", "User": echo.Map{ "UserID": row.UserID, "Username": row.Username, @@ -139,7 +146,7 @@ func (h *Handler) postUserFetchIcon(c echo.Context) error { // The failure is intentionally ignored. Retry manually if needed. } }() - return c.Redirect(http.StatusSeeOther, "/iosdc-japan/2024/code-battle/admin/users") + return c.Redirect(http.StatusSeeOther, basePath+"/admin/users") } func (h *Handler) getGames(c echo.Context) error { @@ -165,8 +172,9 @@ func (h *Handler) getGames(c echo.Context) error { } return c.Render(http.StatusOK, "games", echo.Map{ - "Title": "Games", - "Games": games, + "BasePath": basePath, + "Title": "Games", + "Games": games, }) } @@ -189,7 +197,8 @@ func (h *Handler) getGameEdit(c echo.Context) error { } return c.Render(http.StatusOK, "game_edit", echo.Map{ - "Title": "Game Edit", + "BasePath": basePath, + "Title": "Game Edit", "Game": echo.Map{ "GameID": row.GameID, "GameType": row.GameType, @@ -278,5 +287,5 @@ func (h *Handler) postGameEdit(c echo.Context) error { } } - return c.Redirect(http.StatusSeeOther, c.Request().URL.Path) + return c.Redirect(http.StatusSeeOther, basePath+"/admin/games") } diff --git a/backend/admin/templates/base.html b/backend/admin/templates/base.html index 49e2066..8e71194 100644 --- a/backend/admin/templates/base.html +++ b/backend/admin/templates/base.html @@ -2,9 +2,9 @@ <html> <head> <title>ADMIN {{ .Title }} | iOSDC Japan 2024 Albatross.swift</title> - <link rel="icon" href="/iosdc-japan/2024/code-battle/favicon.svg"> - <link rel="stylesheet" href="/iosdc-japan/2024/code-battle/admin/css/normalize.css"> - <link rel="stylesheet" href="/iosdc-japan/2024/code-battle/admin/css/sakura.css"> + <link rel="icon" href="{{ .BasePath }}/favicon.svg"> + <link rel="stylesheet" href="{{ .BasePath }}/admin/css/normalize.css"> + <link rel="stylesheet" href="{{ .BasePath }}/admin/css/sakura.css"> </head> <body> <section> diff --git a/backend/admin/templates/dashboard.html b/backend/admin/templates/dashboard.html index b2037cb..15b10ff 100644 --- a/backend/admin/templates/dashboard.html +++ b/backend/admin/templates/dashboard.html @@ -2,12 +2,12 @@ {{ define "content" }} <p> - <a href="/iosdc-japan/2024/code-battle/admin/users">Users</a> + <a href="{{ .BasePath }}/admin/users">Users</a> </p> <p> - <a href="/iosdc-japan/2024/code-battle/admin/games">Games</a> + <a href="{{ .BasePath }}/admin/games">Games</a> </p> -<form method="post" action="/iosdc-japan/2024/code-battle/logout"> +<form method="post" action="{{ .BasePath }}/logout"> <button type="submit">Logout</button> </form> {{ end }} diff --git a/backend/admin/templates/game_edit.html b/backend/admin/templates/game_edit.html index 66f3b9e..48a0625 100644 --- a/backend/admin/templates/game_edit.html +++ b/backend/admin/templates/game_edit.html @@ -1,7 +1,7 @@ {{ template "base.html" . }} {{ define "breadcrumb" }} -<a href="/iosdc-japan/2024/code-battle/admin/dashboard">Dashboard</a> | <a href="/iosdc-japan/2024/code-battle/admin/games">Games</a> +<a href="{{ .BasePath }}/admin/dashboard">Dashboard</a> | <a href="{{ .BasePath }}/admin/games">Games</a> {{ end }} {{ define "content" }} diff --git a/backend/admin/templates/games.html b/backend/admin/templates/games.html index 6d6bd68..9dd9cae 100644 --- a/backend/admin/templates/games.html +++ b/backend/admin/templates/games.html @@ -1,20 +1,20 @@ {{ template "base.html" . }} {{ define "breadcrumb" }} -<a href="/iosdc-japan/2024/code-battle/admin/dashboard">Dashboard</a> +<a href="{{ .BasePath }}/admin/dashboard">Dashboard</a> {{ end }} {{ define "content" }} <ul> {{ range .Games }} <li> - <a href="/iosdc-japan/2024/code-battle/admin/games/{{ .GameID }}"> + <a href="{{ $.BasePath }}/admin/games/{{ .GameID }}"> {{ .DisplayName }} (id={{ .GameID }} type={{ .GameType }} state={{ .State }}) </a> <ul> {{ if and (ne .State "closed") (ne .State "finished") }} <li> - <a href="/iosdc-japan/2024/code-battle/golf/{{ .GameID }}/watch">Watch</a> + <a href="{{ $.BasePath }}/golf/{{ .GameID }}/watch">Watch</a> </li> {{ end }} </ul> diff --git a/backend/admin/templates/user_edit.html b/backend/admin/templates/user_edit.html index 56ecbc8..d31338a 100644 --- a/backend/admin/templates/user_edit.html +++ b/backend/admin/templates/user_edit.html @@ -1,7 +1,7 @@ {{ template "base.html" . }} {{ define "breadcrumb" }} -<a href="/iosdc-japan/2024/code-battle/admin/dashboard">Dashboard</a> | <a href="/iosdc-japan/2024/code-battle/admin/users">Users</a> +<a href="{{ .BasePath }}/admin/dashboard">Dashboard</a> | <a href="{{ .BasePath }}/admin/users">Users</a> {{ end }} {{ define "content" }} diff --git a/backend/admin/templates/users.html b/backend/admin/templates/users.html index 3dc03c0..36fae0d 100644 --- a/backend/admin/templates/users.html +++ b/backend/admin/templates/users.html @@ -1,17 +1,17 @@ {{ template "base.html" . }} {{ define "breadcrumb" }} -<a href="/iosdc-japan/2024/code-battle/admin/dashboard">Dashboard</a> +<a href="{{ .BasePath }}/admin/dashboard">Dashboard</a> {{ end }} {{ define "content" }} <ul> {{ range .Users }} <li> - <a href="/iosdc-japan/2024/code-battle/admin/users/{{ .UserID }}"> + <a href="{{ $.BasePath }}/admin/users/{{ .UserID }}"> {{ .DisplayName }} (id={{ .UserID }} username={{ .Username }}){{ if .IsAdmin }} <em>admin</em>{{ end }} </a> - <form method="post" action="/iosdc-japan/2024/code-battle/admin/users/{{ .UserID }}/fetch-icon"> + <form method="post" action="{{ $.BasePath }}/admin/users/{{ .UserID }}/fetch-icon"> <button type="submit">Fetch Icon</button> </form> </li> |
