2020-04-27 22:43:42 +02:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
2020-05-03 19:19:28 +02:00
|
|
|
"net/http"
|
|
|
|
"path"
|
|
|
|
|
2020-04-27 22:43:42 +02:00
|
|
|
"forge.cadoles.com/wpetit/guesstimate/internal/config"
|
|
|
|
"github.com/go-chi/chi"
|
2020-05-03 19:19:28 +02:00
|
|
|
"gitlab.com/wpetit/goweb/static"
|
2020-04-27 22:43:42 +02:00
|
|
|
)
|
|
|
|
|
2020-06-15 21:05:28 +02:00
|
|
|
// Mount endoints for server app
|
2020-04-27 22:43:42 +02:00
|
|
|
func Mount(r *chi.Mux, config *config.Config) error {
|
2020-05-03 18:34:44 +02:00
|
|
|
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)
|
|
|
|
})
|
2020-04-27 22:43:42 +02:00
|
|
|
|
2020-06-15 21:05:28 +02:00
|
|
|
r.Route("/export", func(r chi.Router) {
|
|
|
|
r.Get("/projects/{projectID}", handleExportProject)
|
|
|
|
})
|
|
|
|
|
2020-05-03 19:19:28 +02:00
|
|
|
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)
|
2020-06-15 21:05:28 +02:00
|
|
|
r.Get("/pdf/*", serveClientIndex)
|
2020-05-03 19:19:28 +02:00
|
|
|
|
|
|
|
notFoundHandler := r.NotFoundHandler()
|
|
|
|
r.Get("/*", static.Dir(config.HTTP.PublicDir, "", notFoundHandler))
|
|
|
|
|
2020-04-27 22:43:42 +02:00
|
|
|
return nil
|
|
|
|
}
|