feat: serve frontend
This commit is contained in:
@ -5,7 +5,6 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.local/admin/hspguard/internal/auth"
|
||||
imiddleware "gitea.local/admin/hspguard/internal/middleware"
|
||||
@ -31,18 +30,27 @@ func (s *APIServer) Run() error {
|
||||
router := chi.NewRouter()
|
||||
router.Use(middleware.Logger)
|
||||
|
||||
workDir, _ := os.Getwd()
|
||||
staticDir := http.Dir(filepath.Join(workDir, "static"))
|
||||
FileServer(router, "/static", staticDir)
|
||||
// workDir, _ := os.Getwd()
|
||||
// staticDir := http.Dir(filepath.Join(workDir, "static"))
|
||||
// FileServer(router, "/static", staticDir)
|
||||
|
||||
router.Route("/api/v1", func(r chi.Router) {
|
||||
r.Use(imiddleware.WithSkipper(imiddleware.AuthMiddleware, "/api/v1/login", "/api/v1/register"))
|
||||
|
||||
userHandler := user.NewUserHandler(s.repo)
|
||||
userHandler.RegisterRoutes(router, r)
|
||||
userHandler.RegisterRoutes(r)
|
||||
|
||||
authHandler := auth.NewAuthHandler(s.repo)
|
||||
authHandler.RegisterRoutes(router, r)
|
||||
authHandler.RegisterRoutes(r)
|
||||
})
|
||||
|
||||
router.Get("/*", func(w http.ResponseWriter, r *http.Request) {
|
||||
path := "./dist" + r.URL.Path
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
http.ServeFile(w, r, "./dist/index.html")
|
||||
return
|
||||
}
|
||||
http.FileServer(http.Dir("./dist")).ServeHTTP(w, r)
|
||||
})
|
||||
|
||||
// Handle unknown routes
|
||||
|
Reference in New Issue
Block a user