You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
797 B

  1. package Frontend
  2. import (
  3. "io/fs"
  4. "net/http"
  5. "github.com/gorilla/mux"
  6. )
  7. const (
  8. indexPath = "Frontend/vue/dist/index.html"
  9. )
  10. var (
  11. routes []string = []string{
  12. "/admin/login",
  13. "/admin/signup",
  14. "/admin/users",
  15. }
  16. )
  17. func indexHandler(entrypoint string) func(w http.ResponseWriter, r *http.Request) {
  18. fn := func(w http.ResponseWriter, r *http.Request) {
  19. http.ServeFile(w, r, entrypoint)
  20. }
  21. return http.HandlerFunc(fn)
  22. }
  23. func InitFrontendRoutes(router *mux.Router) {
  24. var (
  25. frontendFS http.Handler
  26. stripped fs.FS
  27. route string
  28. )
  29. stripped = GetFrontendAssets()
  30. frontendFS = http.FileServer(http.FS(stripped))
  31. for _, route = range routes {
  32. router.
  33. PathPrefix(route).
  34. HandlerFunc(indexHandler(indexPath))
  35. }
  36. router.PathPrefix("/").Handler(frontendFS)
  37. }