This commit is contained in:
Gerasimos Maropoulos 2016-08-16 13:17:26 +03:00
parent c6f5406c3b
commit ca2e46f1c3
2 changed files with 13 additions and 6 deletions

10
iris.go
View File

@ -705,7 +705,11 @@ func Lookups() []Route {
// Lookup returns a registed route by its name
func (s *Framework) Lookup(routeName string) Route {
return s.mux.lookup(routeName)
r := s.mux.lookup(routeName)
if nil == r {
return nil
}
return r
}
// Lookups returns all registed routes
@ -1050,7 +1054,7 @@ type (
StaticFS(string, string, int) RouteNameFunc
StaticWeb(string, string, int) RouteNameFunc
StaticServe(string, ...string) RouteNameFunc
StaticContent(string, string, []byte) func(string)
StaticContent(string, string, []byte) RouteNameFunc
Favicon(string, ...string) RouteNameFunc
// templates
@ -1739,7 +1743,7 @@ func StaticContent(reqPath string, contentType string, content []byte) RouteName
// StaticContent serves bytes, memory cached, on the reqPath
// a good example of this is how the websocket server uses that to auto-register the /iris-ws.js
func (api *muxAPI) StaticContent(reqPath string, cType string, content []byte) func(string) { // func(string) because we use that on websockets
func (api *muxAPI) StaticContent(reqPath string, cType string, content []byte) RouteNameFunc { // func(string) because we use that on websockets
modtime := time.Now()
modtimeStr := modtime.UTC().Format(config.TimeFormat)
h := func(ctx *Context) {

View File

@ -51,10 +51,13 @@ func RegisterWebsocketServer(station FrameworkAPI, server WebsocketServer, logge
}
}
}
clientSideLookupName := "iris-websocket-client-side"
station.Get(c.Endpoint, websocketHandler)
// serve the client side on domain:port/iris-ws.js
station.StaticContent("/iris-ws.js", "application/json", websocketClientSource)
// check if client side already exists
if station.Lookup(clientSideLookupName) == nil {
// serve the client side on domain:port/iris-ws.js
station.StaticContent("/iris-ws.js", "application/json", websocketClientSource)(clientSideLookupName)
}
}