mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-18 16:38:38 +00:00
Fix routing in frontend not working (#723)
This commit is contained in:
parent
0abd7c06ff
commit
4be7164f20
@ -62,7 +62,6 @@ const (
|
|||||||
socketConnectionRetries = 30
|
socketConnectionRetries = 30
|
||||||
socketConnectionRetryDelay = time.Second * 2
|
socketConnectionRetryDelay = time.Second * 2
|
||||||
socketHandshakeTimeout = time.Second * 2
|
socketHandshakeTimeout = time.Second * 2
|
||||||
uiIndexPath = "./site/index.html"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -248,16 +247,23 @@ func hostApi(socketHarOutputChannel chan<- *tapApi.OutputChannelItem) {
|
|||||||
|
|
||||||
app.Use(DisableRootStaticCache())
|
app.Use(DisableRootStaticCache())
|
||||||
|
|
||||||
if err := setUIFlags(); err != nil {
|
var staticFolder string
|
||||||
logger.Log.Errorf("Error setting ui mode, err: %v", err)
|
if config.Config.StandaloneMode {
|
||||||
|
staticFolder = "./site-standalone"
|
||||||
|
} else {
|
||||||
|
staticFolder = "./site"
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Config.StandaloneMode {
|
indexStaticFile := staticFolder + "/index.html"
|
||||||
app.Use(static.ServeRoot("/", "./site-standalone"))
|
if err := setUIFlags(indexStaticFile); err != nil {
|
||||||
} else {
|
logger.Log.Errorf("Error setting ui flags, err: %v", err)
|
||||||
app.Use(static.ServeRoot("/", "./site"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.Use(static.ServeRoot("/", staticFolder))
|
||||||
|
app.NoRoute(func(c *gin.Context) {
|
||||||
|
c.File(indexStaticFile)
|
||||||
|
})
|
||||||
|
|
||||||
app.Use(middlewares.CORSMiddleware()) // This has to be called after the static middleware, does not work if its called before
|
app.Use(middlewares.CORSMiddleware()) // This has to be called after the static middleware, does not work if its called before
|
||||||
|
|
||||||
api.WebSocketRoutes(app, &eventHandlers, startTime)
|
api.WebSocketRoutes(app, &eventHandlers, startTime)
|
||||||
@ -278,7 +284,6 @@ func hostApi(socketHarOutputChannel chan<- *tapApi.OutputChannelItem) {
|
|||||||
routes.EntriesRoutes(app)
|
routes.EntriesRoutes(app)
|
||||||
routes.MetadataRoutes(app)
|
routes.MetadataRoutes(app)
|
||||||
routes.StatusRoutes(app)
|
routes.StatusRoutes(app)
|
||||||
routes.NotFoundRoute(app)
|
|
||||||
utils.StartServer(app)
|
utils.StartServer(app)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,7 +298,7 @@ func DisableRootStaticCache() gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUIFlags() error {
|
func setUIFlags(uiIndexPath string) error {
|
||||||
read, err := ioutil.ReadFile(uiIndexPath)
|
read, err := ioutil.ReadFile(uiIndexPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package routes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NotFoundRoute defines the 404 Error route.
|
|
||||||
func NotFoundRoute(app *gin.Engine) {
|
|
||||||
app.Use(
|
|
||||||
func(c *gin.Context) {
|
|
||||||
c.JSON(http.StatusNotFound, map[string]interface{}{
|
|
||||||
"error": true,
|
|
||||||
"msg": "sorry, endpoint is not found",
|
|
||||||
})
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user