@@ -2,6 +2,7 @@ package router
2
2
3
3
import (
4
4
"fmt"
5
+ "net/http"
5
6
"regexp"
6
7
"strings"
7
8
@@ -10,8 +11,9 @@ import (
10
11
11
12
"github.com/onflow/flow-go/access"
12
13
"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"
14
15
"github.com/onflow/flow-go/engine/access/rest/http/models"
16
+ "github.com/onflow/flow-go/engine/access/rest/websockets"
15
17
legacyws "github.com/onflow/flow-go/engine/access/rest/websockets/legacy"
16
18
"github.com/onflow/flow-go/engine/access/state_stream"
17
19
"github.com/onflow/flow-go/engine/access/state_stream/backend"
@@ -54,7 +56,7 @@ func (b *RouterBuilder) AddRestRoutes(
54
56
) * RouterBuilder {
55
57
linkGenerator := models .NewLinkGeneratorImpl (b .v1SubRouter )
56
58
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 )
58
60
b .v1SubRouter .
59
61
Methods (r .Method ).
60
62
Path (r .Pattern ).
@@ -64,8 +66,8 @@ func (b *RouterBuilder) AddRestRoutes(
64
66
return b
65
67
}
66
68
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 (
69
71
stateStreamApi state_stream.API ,
70
72
chain flow.Chain ,
71
73
stateStreamConfig backend.Config ,
@@ -84,6 +86,23 @@ func (b *RouterBuilder) AddWsLegacyRoutes(
84
86
return b
85
87
}
86
88
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
+
87
106
func (b * RouterBuilder ) Build () * mux.Router {
88
107
return b .router
89
108
}
0 commit comments