|
|
- package Frontend
-
- import (
- "io/fs"
- "net/http"
-
- "github.com/gorilla/mux"
- )
-
- const (
- indexPath = "Frontend/vue/dist/index.html"
- )
-
- var (
- routes []string = []string{
- "/admin/login",
- "/admin/signup",
- "/admin/users",
- "/admin/users/new",
- "/admin/users/{id}",
- }
- )
-
- func indexHandler(entrypoint string) func(w http.ResponseWriter, r *http.Request) {
- fn := func(w http.ResponseWriter, r *http.Request) {
- http.ServeFile(w, r, entrypoint)
- }
-
- return http.HandlerFunc(fn)
- }
-
- func InitFrontendRoutes(router *mux.Router) {
- var (
- frontendFS http.Handler
- stripped fs.FS
- route string
- )
-
- stripped = GetFrontendAssets()
-
- frontendFS = http.FileServer(http.FS(stripped))
-
- for _, route = range routes {
- router.
- PathPrefix(route).
- HandlerFunc(indexHandler(indexPath))
- }
-
- router.PathPrefix("/").Handler(frontendFS)
-
- }
|