Skip to content

Commit d06e513

Browse files
Updated routes of websockets for query and CORS
1 parent ebacde1 commit d06e513

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

api/routes/routes.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,35 @@ import (
1313
/* all routes for all features are registered here */
1414
func RegisterRoutes(mux *http.ServeMux, sessionManager *session.Manager) {
1515

16+
allowedOrigin := []string{"http://localhost:3000"}
17+
allowedMethods := []string{"GET", "POST", "OPTIONS"}
18+
allowedHeaders := []string{"Content-Type", "Authorization"}
19+
1620
/* for logging into the backend and creating a session */
1721
mux.HandleFunc("POST /login",
18-
middleware.LoggingMiddleware(auth.LoginHandler(sessionManager)),
22+
middleware.CORSMiddleware(
23+
middleware.LoggingMiddleware(
24+
auth.LoginHandler(sessionManager),
25+
),
26+
allowedOrigin,
27+
allowedMethods,
28+
allowedHeaders,
29+
),
30+
)
31+
32+
/* handle OPTIONS preflight requests for /login */
33+
mux.HandleFunc("OPTIONS /login",
34+
middleware.CORSMiddleware(
35+
func(w http.ResponseWriter, r *http.Request) {
36+
/*
37+
This handler will never be called because CORSMiddleware handles OPTIONS
38+
but we need it for the route to be registered
39+
*/
40+
},
41+
allowedOrigin,
42+
allowedMethods,
43+
allowedHeaders,
44+
),
1945
)
2046

2147
/* for monitoring the state of overall server and laclm backend */
@@ -46,12 +72,21 @@ func RegisterRoutes(mux *http.ServeMux, sessionManager *session.Manager) {
4672
))
4773

4874
/* websocket connection for streaming user transactions data from Redis */
49-
mux.Handle("/users/transactions", http.HandlerFunc(
75+
mux.Handle("/users/transactions/results", http.HandlerFunc(
5076
middleware.LoggingMiddleware(
51-
middleware.AuthenticationMiddleware(sessionManager.StreamUserTransactions),
77+
middleware.AuthenticationQueryMiddleware(sessionManager.StreamUserTransactionsResults),
5278
),
5379
))
5480

81+
/* websocket connection for streaming user transactions data from Redis */
82+
mux.Handle("/users/transactions/pending", http.HandlerFunc(
83+
middleware.LoggingMiddleware(
84+
middleware.AuthenticationQueryMiddleware(sessionManager.StreamUserTransactionsPending),
85+
),
86+
))
87+
88+
/* ARCHIVE WILL BE MADE POST REQUEST */
89+
5590
/* websocket connection for streaming user session data from PostgreSQL database (archived sessions) */
5691
mux.Handle("/users/archive/session", http.HandlerFunc(
5792
middleware.LoggingMiddleware(

0 commit comments

Comments
 (0)