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.

51 lines
837 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. "/admin/users/new",
  16. "/admin/posts",
  17. }
  18. )
  19. func indexHandler(entrypoint string) func(w http.ResponseWriter, r *http.Request) {
  20. fn := func(w http.ResponseWriter, r *http.Request) {
  21. http.ServeFile(w, r, entrypoint)
  22. }
  23. return http.HandlerFunc(fn)
  24. }
  25. func InitFrontendRoutes(router *mux.Router) {
  26. var (
  27. frontendFS http.Handler
  28. stripped fs.FS
  29. route string
  30. )
  31. stripped = GetFrontendAssets()
  32. frontendFS = http.FileServer(http.FS(stripped))
  33. for _, route = range routes {
  34. router.
  35. PathPrefix(route).
  36. HandlerFunc(indexHandler(indexPath))
  37. }
  38. router.PathPrefix("/").Handler(frontendFS)
  39. }