@@ -125,24 +125,32 @@ func (s *Server) Initialize() *fiber.App {
125125}
126126
127127func (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" )
0 commit comments