mirror of
https://github.com/kataras/iris.git
synced 2025-03-13 21:36:28 +01:00
Fix multi websocket servers https://github.com/kataras/iris/issues/365
This commit is contained in:
parent
c6f5406c3b
commit
ca2e46f1c3
10
iris.go
10
iris.go
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user