Skip to content

Commit e36a64e

Browse files
committed
fix: 400 error on websocket connection
1 parent 791934e commit e36a64e

6 files changed

Lines changed: 477 additions & 15 deletions

File tree

.vscode/launch.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@
123123
"--watch-ports",
124124
"-p",
125125
"9190",
126-
"--idle"
126+
"--idle",
127+
"--jwks-server",
128+
"https://auth.druid.gg/.well_known/jwks.json"
127129
],
128130
},
129131
{

cmd/server/web/server.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,32 @@ func (s *Server) Initialize() *fiber.App {
125125
}
126126

127127
func (s *Server) SetAPI(app *fiber.App) *fiber.App {
128+
// Apply global middleware
128129
app.Use(s.headerMiddleware)
130+
app.Use(s.corsMiddleware)
131+
132+
// Create completely isolated websocket routes FIRST to avoid any middleware pollution
129133
wsRoutes := app.Group("/ws/v1")
130-
v1 := app.Use(s.corsMiddleware).Group("/api/v1")
134+
wsRoutes.Use(s.tokenAuthenticationMiddleware)
135+
136+
// Define websocket routes immediately after creating the group
137+
wsRoutes.Get("/serve/:console", websocket.New(s.websocketHandler.HandleProcess)).Name("ws.serve")
138+
wsRoutes.Get("/dev/notify", websocket.New(s.uiDevHandler.NotifyChange)).Name("ws.dev.notify")
139+
140+
// Now create other route groups
141+
v1 := app.Group("/api/v1")
131142
apiRoutes := v1.Group("/")
132143
webdavRoutes := app.Group("/webdav")
133144

134-
privateUiRoutes := app.Use(s.corsMiddleware)
135-
publicUiRoutes := app.Use(s.corsMiddleware)
145+
// Create properly isolated UI route groups
146+
privateUiRoutes := app.Group("")
147+
publicUiRoutes := app.Group("")
136148

137149
if s.jwtMiddleware != nil {
138150
apiRoutes.Use(s.jwtMiddleware, s.injectUserMiddleware)
139151
webdavRoutes.Use(s.jwtMiddleware, s.injectUserMiddleware)
140152
privateUiRoutes.Use(s.jwtMiddleware, s.injectUserMiddleware)
141-
}
142-
143-
wsRoutes.Use(s.tokenAuthenticationMiddleware)
144-
145-
//Scroll Group
153+
} //Scroll Group
146154
apiRoutes.Get("/scroll", s.scrollHandler.GetScroll).Name("scrolls.current")
147155
apiRoutes.Post("/command", s.scrollHandler.RunCommand).Name("command.start")
148156
apiRoutes.Post("/procedure", s.scrollHandler.RunProcedure).Name("procedure.start")
@@ -187,9 +195,6 @@ func (s *Server) SetAPI(app *fiber.App) *fiber.App {
187195

188196
webdavRoutes.Use("*", adaptor.HTTPHandler(webdavHandler))
189197

190-
wsRoutes.Get("/serve/:console", websocket.New(s.websocketHandler.HandleProcess)).Name("ws.serve")
191-
wsRoutes.Get("/dev/notify", websocket.New(s.uiDevHandler.NotifyChange)).Name("ws.dev.notify")
192-
193198
apiRoutes.Get("/ports", s.portHandler.GetPorts).Name("ports.list")
194199

195200
publicUiRoutes.Get("/public/index", s.uiHandler.PublicIndex).Name("ui.public_index")

docs/docs.go

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,96 @@ const docTemplate = `{
120120
}
121121
}
122122
},
123+
"/api/v1/dev/disable": {
124+
"post": {
125+
"consumes": [
126+
"application/json"
127+
],
128+
"produces": [
129+
"application/json"
130+
],
131+
"tags": [
132+
"ui",
133+
"dev",
134+
"druid",
135+
"daemon"
136+
],
137+
"summary": "Disable development mode",
138+
"operationId": "disableDev",
139+
"responses": {
140+
"200": {
141+
"description": "OK",
142+
"schema": {
143+
"$ref": "#/definitions/DevModeResponse"
144+
}
145+
},
146+
"500": {
147+
"description": "Internal Server Error",
148+
"schema": {
149+
"$ref": "#/definitions/ErrorResponse"
150+
}
151+
}
152+
}
153+
}
154+
},
155+
"/api/v1/dev/enable": {
156+
"post": {
157+
"consumes": [
158+
"application/json"
159+
],
160+
"produces": [
161+
"application/json"
162+
],
163+
"tags": [
164+
"ui",
165+
"dev",
166+
"druid",
167+
"daemon"
168+
],
169+
"summary": "Enable development mode",
170+
"operationId": "enableDev",
171+
"responses": {
172+
"200": {
173+
"description": "OK",
174+
"schema": {
175+
"$ref": "#/definitions/DevModeResponse"
176+
}
177+
},
178+
"500": {
179+
"description": "Internal Server Error",
180+
"schema": {
181+
"$ref": "#/definitions/ErrorResponse"
182+
}
183+
}
184+
}
185+
}
186+
},
187+
"/api/v1/dev/status": {
188+
"get": {
189+
"consumes": [
190+
"application/json"
191+
],
192+
"produces": [
193+
"application/json"
194+
],
195+
"tags": [
196+
"ui",
197+
"dev",
198+
"druid",
199+
"daemon"
200+
],
201+
"summary": "Get development mode status",
202+
"operationId": "getDevStatus",
203+
"responses": {
204+
"200": {
205+
"description": "OK",
206+
"schema": {
207+
"$ref": "#/definitions/DevStatusResponse"
208+
}
209+
}
210+
}
211+
}
212+
},
123213
"/api/v1/health": {
124214
"get": {
125215
"consumes": [
@@ -462,6 +552,50 @@ const docTemplate = `{
462552
}
463553
}
464554
}
555+
},
556+
"/private/index": {
557+
"get": {
558+
"consumes": [
559+
"*/*"
560+
],
561+
"produces": [
562+
"text/html"
563+
],
564+
"tags": [
565+
"ui",
566+
"druid",
567+
"daemon"
568+
],
569+
"summary": "Serve private UI index",
570+
"operationId": "getPrivateUIIndex",
571+
"responses": {
572+
"200": {
573+
"description": "OK"
574+
}
575+
}
576+
}
577+
},
578+
"/public/index": {
579+
"get": {
580+
"consumes": [
581+
"*/*"
582+
],
583+
"produces": [
584+
"text/html"
585+
],
586+
"tags": [
587+
"ui",
588+
"druid",
589+
"daemon"
590+
],
591+
"summary": "Serve public UI index",
592+
"operationId": "getPublicUIIndex",
593+
"responses": {
594+
"200": {
595+
"description": "OK"
596+
}
597+
}
598+
}
465599
}
466600
},
467601
"definitions": {
@@ -517,6 +651,42 @@ const docTemplate = `{
517651
}
518652
}
519653
},
654+
"DevModeResponse": {
655+
"type": "object",
656+
"properties": {
657+
"enabled": {
658+
"type": "boolean"
659+
},
660+
"status": {
661+
"type": "string"
662+
}
663+
}
664+
},
665+
"DevStatusResponse": {
666+
"type": "object",
667+
"properties": {
668+
"enabled": {
669+
"type": "boolean"
670+
},
671+
"watchedPaths": {
672+
"type": "array",
673+
"items": {
674+
"type": "string"
675+
}
676+
}
677+
}
678+
},
679+
"ErrorResponse": {
680+
"type": "object",
681+
"properties": {
682+
"error": {
683+
"type": "string"
684+
},
685+
"status": {
686+
"type": "string"
687+
}
688+
}
689+
},
520690
"Procedure": {
521691
"type": "object",
522692
"properties": {

0 commit comments

Comments
 (0)