guesstimate/server/internal/route/mount.go

39 lines
979 B
Go

package route
import (
"net/http"
"path"
"forge.cadoles.com/wpetit/guesstimate/internal/config"
"github.com/go-chi/chi"
"gitlab.com/wpetit/goweb/static"
)
// Mount endoints for server app
func Mount(r *chi.Mux, config *config.Config) error {
r.Route("/api/v1", func(r chi.Router) {
r.Get("/projects/{projectID}", handleGetProject)
r.Post("/projects/{projectID}", handleCreateProject)
r.Patch("/projects/{projectID}", handlePatchProject)
r.Delete("/projects/{projectID}", handleDeleteProject)
})
r.Route("/export", func(r chi.Router) {
r.Get("/projects/{projectID}", handleExportProject)
})
clientIndex := path.Join(config.HTTP.PublicDir, "index.html")
serveClientIndex := func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, clientIndex)
}
r.Get("/p/*", serveClientIndex)
r.Get("/pdf/*", serveClientIndex)
notFoundHandler := r.NotFoundHandler()
r.Get("/*", static.Dir(config.HTTP.PublicDir, "", notFoundHandler))
return nil
}