Add routing for basic web ui

This commit is contained in:
Deluan
2020-01-19 19:34:54 -05:00
parent 5bc1551b09
commit 3a03284c59
8 changed files with 112 additions and 29 deletions
+33
View File
@@ -0,0 +1,33 @@
package app
import (
"net/http"
"github.com/cloudsonic/sonic-server/model"
"github.com/cloudsonic/sonic-server/server"
"github.com/go-chi/chi"
)
type Router struct {
ds model.DataStore
mux http.Handler
path string
}
func New(ds model.DataStore, path string) *Router {
r := &Router{ds: ds, path: path}
r.mux = r.routes()
return r
}
func (app *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
app.mux.ServeHTTP(w, r)
}
func (app *Router) routes() http.Handler {
r := chi.NewRouter()
server.FileServer(r, app.path, "/", http.Dir("ui/build"))
r.Get("/ping", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(`{"response":"pong"}`)) })
return r
}