Skip to content

Commit ac45f06

Browse files
authored
Merge pull request #6 from tgg/feature/static_serve
[feature/static_serve] adding pathprefix app-array for front-end (usi…
2 parents d9e4a1b + 7d61f46 commit ac45f06

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func main() {
2222
Router: mux.NewRouter(),
2323
}
2424
router.AddHandledFunctions()
25+
router.AddStaticFiles()
2526
router.RegisterSignalRRoute("/model", NewModelHub())
2627
log.Println("SignalR server created")
2728

muxroutersignalr.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,25 @@ type MuxRouterSignalR struct {
1919
}
2020

2121
func (router *MuxRouterSignalR) HandleFunc(path string, f func(w http.ResponseWriter, r *http.Request)) {
22-
router.NewRoute().Path(path).HandlerFunc(f)
22+
router.HandleFuncRoute(path, f)
23+
}
24+
25+
func (router *MuxRouterSignalR) HandleFuncRoute(path string, f func(w http.ResponseWriter, r *http.Request)) *mux.Route {
26+
route := router.NewRoute().Path(path).HandlerFunc(f)
2327
router.paths = append(router.paths, path)
2428
log.Printf("Route %s registered\n", path)
29+
return route
2530
}
2631

2732
func (router *MuxRouterSignalR) Handle(path string, handler http.Handler) {
28-
router.NewRoute().Path(path).Handler(handler)
33+
router.HandleRoute(path, handler)
34+
}
35+
36+
func (router *MuxRouterSignalR) HandleRoute(path string, handler http.Handler) *mux.Route {
37+
route := router.NewRoute().Path(path).Handler(handler)
2938
router.paths = append(router.paths, path)
3039
log.Printf("Route %s registered\n", path)
40+
return route
3141
}
3242

3343
func WithMuxRouter(router *MuxRouterSignalR) func() signalr.MappableRouter {
@@ -36,6 +46,10 @@ func WithMuxRouter(router *MuxRouterSignalR) func() signalr.MappableRouter {
3646
}
3747
}
3848

49+
func (router *MuxRouterSignalR) AddStaticFiles() {
50+
router.PathPrefix("/app-array/").Handler(http.StripPrefix("/app-array/", http.FileServer(http.Dir("./build/"))))
51+
}
52+
3953
func (router *MuxRouterSignalR) AddHandledFunctions() {
4054
router.HandleFunc("/models/{id}", func(writer http.ResponseWriter, request *http.Request) {
4155
vars := mux.Vars(request)

0 commit comments

Comments
 (0)