Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func main() {
Router: mux.NewRouter(),
}
router.AddHandledFunctions()
router.AddStaticFiles()
router.RegisterSignalRRoute("/model", NewModelHub())
log.Println("SignalR server created")

Expand Down
18 changes: 16 additions & 2 deletions muxroutersignalr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@ type MuxRouterSignalR struct {
}

func (router *MuxRouterSignalR) HandleFunc(path string, f func(w http.ResponseWriter, r *http.Request)) {
router.NewRoute().Path(path).HandlerFunc(f)
router.HandleFuncRoute(path, f)
}

func (router *MuxRouterSignalR) HandleFuncRoute(path string, f func(w http.ResponseWriter, r *http.Request)) *mux.Route {
route := router.NewRoute().Path(path).HandlerFunc(f)
router.paths = append(router.paths, path)
log.Printf("Route %s registered\n", path)
return route
}

func (router *MuxRouterSignalR) Handle(path string, handler http.Handler) {
router.NewRoute().Path(path).Handler(handler)
router.HandleRoute(path, handler)
}

func (router *MuxRouterSignalR) HandleRoute(path string, handler http.Handler) *mux.Route {
route := router.NewRoute().Path(path).Handler(handler)
router.paths = append(router.paths, path)
log.Printf("Route %s registered\n", path)
return route
}

func WithMuxRouter(router *MuxRouterSignalR) func() signalr.MappableRouter {
Expand All @@ -36,6 +46,10 @@ func WithMuxRouter(router *MuxRouterSignalR) func() signalr.MappableRouter {
}
}

func (router *MuxRouterSignalR) AddStaticFiles() {
router.PathPrefix("/app-array/").Handler(http.StripPrefix("/app-array/", http.FileServer(http.Dir("./build/"))))
}

func (router *MuxRouterSignalR) AddHandledFunctions() {
router.HandleFunc("/models/{id}", func(writer http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request)
Expand Down