mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 23:40:35 +01:00
Fix https://github.com/kataras/go-websocket/issues/27 on iris.v6 too
Former-commit-id: 29b1ea2ff313bdaeb719c242e08c5d5c9149156a
This commit is contained in:
parent
d2aee5e187
commit
86f34dc5df
37
iris.go
37
iris.go
|
@ -288,25 +288,28 @@ func New(setters ...OptionSetter) *Framework {
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Adapt(EventPolicy{Build: func(*Framework) {
|
s.Adapt(EventPolicy{Build: func(*Framework) {
|
||||||
// first check if it's not setted already by any Boot event.
|
// user has registered routes
|
||||||
if s.Router.handler == nil {
|
if s.Router.repository.Len() > 0 {
|
||||||
// and most importantly, check if the user has provided a router
|
// first check if it's not setted already by any Boot event.
|
||||||
// adaptor, if not then it should panic here, iris can't run without a router attached to it
|
if s.Router.handler == nil {
|
||||||
// and default router not any more, user should select one from ./adaptors or
|
// and most importantly, check if the user has provided a router
|
||||||
// any other third-party adaptor may done by community.
|
// adaptor, if not then it should panic here, iris can't run without a router attached to it
|
||||||
// I was coding the new iris version for more than 20 days(~200+ hours of code)
|
// and default router not any more, user should select one from ./adaptors or
|
||||||
// and I hope that once per application the addition of +1 line users have to put,
|
// any other third-party adaptor may done by community.
|
||||||
// is not a big deal.
|
// I was coding the new iris version for more than 20 days(~200+ hours of code)
|
||||||
if s.policies.RouterBuilderPolicy == nil {
|
// and I hope that once per application the addition of +1 line users have to put,
|
||||||
// this is important panic and app can't continue as we said.
|
// is not a big deal.
|
||||||
s.handlePanic(errRouterIsMissing.Format(s.Config.VHost))
|
if s.policies.RouterBuilderPolicy == nil {
|
||||||
// don't trace anything else,
|
// this is important panic and app can't continue as we said.
|
||||||
// the detailed errRouterIsMissing message will tell the user what to do to fix that.
|
s.handlePanic(errRouterIsMissing.Format(s.Config.VHost))
|
||||||
os.Exit(0)
|
// don't trace anything else,
|
||||||
|
// the detailed errRouterIsMissing message will tell the user what to do to fix that.
|
||||||
|
os.Exit(0)
|
||||||
|
|
||||||
|
}
|
||||||
|
// buid the router using user's selection build policy
|
||||||
|
s.Router.build(s.policies.RouterBuilderPolicy)
|
||||||
}
|
}
|
||||||
// buid the router using user's selection build policy
|
|
||||||
s.Router.build(s.policies.RouterBuilderPolicy)
|
|
||||||
}
|
}
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
|
20
websocket.go
20
websocket.go
|
@ -36,13 +36,14 @@ type (
|
||||||
// NewWebsocketServer returns a new empty unitialized websocket server
|
// NewWebsocketServer returns a new empty unitialized websocket server
|
||||||
// it runs on first OnConnection
|
// it runs on first OnConnection
|
||||||
func NewWebsocketServer(station *Framework) *WebsocketServer {
|
func NewWebsocketServer(station *Framework) *WebsocketServer {
|
||||||
return &WebsocketServer{station: station, Server: websocket.New()}
|
return &WebsocketServer{station: station, Server: websocket.New(), Config: DefaultWebsocketConfiguration()}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWebsocketServer creates the client side source route and the route path Endpoint with the correct Handler
|
// NewWebsocketServer creates the client side source route and the route path Endpoint with the correct Handler
|
||||||
// receives the websocket configuration and the iris station
|
// receives the websocket configuration and the iris station
|
||||||
// and returns the websocket server which can be attached to more than one iris station (if needed)
|
// and returns the websocket server which can be attached to more than one iris station (if needed)
|
||||||
func (ws *WebsocketServer) init() {
|
func (ws *WebsocketServer) init() {
|
||||||
|
|
||||||
if ws.Config.Endpoint == "" {
|
if ws.Config.Endpoint == "" {
|
||||||
ws.Config = ws.station.Config.Websocket
|
ws.Config = ws.station.Config.Websocket
|
||||||
}
|
}
|
||||||
|
@ -52,14 +53,6 @@ func (ws *WebsocketServer) init() {
|
||||||
if c.Endpoint == "" {
|
if c.Endpoint == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// set the routing for client-side source (javascript) (optional)
|
|
||||||
clientSideLookupName := "iris-websocket-client-side"
|
|
||||||
ws.station.Get(c.Endpoint, ToHandler(ws.Server.Handler()))
|
|
||||||
// check if client side already exists
|
|
||||||
if ws.station.Routes().Lookup(clientSideLookupName) == nil {
|
|
||||||
// serve the client side on domain:port/iris-ws.js
|
|
||||||
ws.station.StaticContent("/iris-ws.js", contentJavascript, websocket.ClientSource).ChangeName(clientSideLookupName)
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.CheckOrigin == nil {
|
if c.CheckOrigin == nil {
|
||||||
c.CheckOrigin = DefaultWebsocketCheckOrigin
|
c.CheckOrigin = DefaultWebsocketCheckOrigin
|
||||||
|
@ -85,6 +78,15 @@ func (ws *WebsocketServer) init() {
|
||||||
CheckOrigin: c.CheckOrigin,
|
CheckOrigin: c.CheckOrigin,
|
||||||
IDGenerator: c.IDGenerator,
|
IDGenerator: c.IDGenerator,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// set the routing for client-side source (javascript) (optional)
|
||||||
|
clientSideLookupName := "iris-websocket-client-side"
|
||||||
|
ws.station.Get(c.Endpoint, ToHandler(ws.Server.Handler()))
|
||||||
|
// check if client side already exists
|
||||||
|
if ws.station.Routes().Lookup(clientSideLookupName) == nil {
|
||||||
|
// serve the client side on domain:port/iris-ws.js
|
||||||
|
ws.station.StaticContent("/iris-ws.js", contentJavascript, websocket.ClientSource).ChangeName(clientSideLookupName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebsocketConnection is the front-end API that you will use to communicate with the client side
|
// WebsocketConnection is the front-end API that you will use to communicate with the client side
|
||||||
|
|
Loading…
Reference in New Issue
Block a user