@@ -2,6 +2,7 @@ package router
22
33import (
44 "fmt"
5+ "net/http"
56 "regexp"
67 "strings"
78
@@ -10,8 +11,9 @@ import (
1011
1112 "github.com/onflow/flow-go/access"
1213 "github.com/onflow/flow-go/engine/access/rest/common/middleware"
13- "github.com/onflow/flow-go/engine/access/rest/http"
14+ flowhttp "github.com/onflow/flow-go/engine/access/rest/http"
1415 "github.com/onflow/flow-go/engine/access/rest/http/models"
16+ "github.com/onflow/flow-go/engine/access/rest/websockets"
1517 legacyws "github.com/onflow/flow-go/engine/access/rest/websockets/legacy"
1618 "github.com/onflow/flow-go/engine/access/state_stream"
1719 "github.com/onflow/flow-go/engine/access/state_stream/backend"
@@ -54,7 +56,7 @@ func (b *RouterBuilder) AddRestRoutes(
5456) * RouterBuilder {
5557 linkGenerator := models .NewLinkGeneratorImpl (b .v1SubRouter )
5658 for _ , r := range Routes {
57- h := http .NewHandler (b .logger , backend , r .Handler , linkGenerator , chain , maxRequestSize )
59+ h := flowhttp .NewHandler (b .logger , backend , r .Handler , linkGenerator , chain , maxRequestSize )
5860 b .v1SubRouter .
5961 Methods (r .Method ).
6062 Path (r .Pattern ).
@@ -64,8 +66,8 @@ func (b *RouterBuilder) AddRestRoutes(
6466 return b
6567}
6668
67- // AddWsLegacyRoutes adds WebSocket routes to the router.
68- func (b * RouterBuilder ) AddWsLegacyRoutes (
69+ // AddLegacyWebsocketsRoutes adds WebSocket routes to the router.
70+ func (b * RouterBuilder ) AddLegacyWebsocketsRoutes (
6971 stateStreamApi state_stream.API ,
7072 chain flow.Chain ,
7173 stateStreamConfig backend.Config ,
@@ -84,6 +86,23 @@ func (b *RouterBuilder) AddWsLegacyRoutes(
8486 return b
8587}
8688
89+ func (b * RouterBuilder ) AddWebsocketsRoute (
90+ chain flow.Chain ,
91+ config websockets.Config ,
92+ streamApi state_stream.API ,
93+ streamConfig backend.Config ,
94+ maxRequestSize int64 ,
95+ ) * RouterBuilder {
96+ handler := websockets .NewWebSocketHandler (b .logger , config , chain , streamApi , streamConfig , maxRequestSize )
97+ b .v1SubRouter .
98+ Methods (http .MethodGet ).
99+ Path ("/ws" ).
100+ Name ("ws" ).
101+ Handler (handler )
102+
103+ return b
104+ }
105+
87106func (b * RouterBuilder ) Build () * mux.Router {
88107 return b .router
89108}
0 commit comments