38 lines
980 B
Go
38 lines
980 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"forge.cadoles.com/wpetit/goweb/middleware/container"
|
|
"forge.cadoles.com/wpetit/goweb/service/template"
|
|
"forge.cadoles.com/wpetit/goweb/static"
|
|
"github.com/go-chi/chi"
|
|
|
|
"forge.cadoles.com/Pyxis/orion/cmd/server/jsonrpc"
|
|
)
|
|
|
|
func configureRoutes(r *chi.Mux) {
|
|
r.Get("/", serveHomepage)
|
|
r.Get("/modules", serveModulesList)
|
|
r.Post("/rpc", handleJSONRPC)
|
|
r.Get("/**", static.Dir(conf.AssetDir, "", r.NotFoundHandler()))
|
|
}
|
|
|
|
func serveHomepage(w http.ResponseWriter, r *http.Request) {
|
|
http.Redirect(w, r, "/modules", http.StatusFound)
|
|
}
|
|
|
|
func serveModulesList(w http.ResponseWriter, r *http.Request) {
|
|
ctn := container.Must(r.Context())
|
|
templateService := template.Must(ctn)
|
|
if err := templateService.RenderPage(w, "modules_list.html.tmpl", nil); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func handleJSONRPC(w http.ResponseWriter, r *http.Request) {
|
|
ctn := container.Must(r.Context())
|
|
rpcServer := jsonrpc.Must(ctn)
|
|
rpcServer.ServeHTTP(w, r)
|
|
}
|