Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto 2024-10-02 11:16:11 +02:00
parent d7dee3a5ec
commit 8f507c39c0
6 changed files with 776 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import (
"net/http"
"github.com/dave-gray101/v2keyauth"
"github.com/gofiber/websocket/v2"
"github.com/mudler/LocalAI/pkg/utils"
"github.com/mudler/LocalAI/core/http/endpoints/localai"
@ -181,6 +182,16 @@ func API(application *application.Application) (*fiber.App, error) {
Browse: true,
}))
app.Use("/ws", func(c *fiber.Ctx) error {
// IsWebSocketUpgrade returns true if the client
// requested upgrade to the WebSocket protocol.
if websocket.IsWebSocketUpgrade(c) {
c.Locals("allowed", true)
return c.Next()
}
return fiber.ErrUpgradeRequired
})
// Define a custom 404 handler
// Note: keep this at the bottom!
router.Use(notFoundHandler)