Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: use echo static middleware to serve dist (#1814)

boojackbd4e3c9b877f
diff --git a/server/server_frontend_embed.go b/server/server_frontend_embed.go
index 4a5dcb90c0..72aad27a14 100644
--- a/server/server_frontend_embed.go
+++ b/server/server_frontend_embed.go
@@ -9,14 +9,12 @@ import (
"net/http"
"github.com/labstack/echo/v4"
+ "github.com/labstack/echo/v4/middleware"
)
//go:embed dist
var embeddedFiles embed.FS
-//go:embed dist/index.html
-var indexContent string
-
func getFileSystem() http.FileSystem {
fs, err := fs.Sub(embeddedFiles, "dist")
if err != nil {
@@ -27,12 +25,10 @@ func getFileSystem() http.FileSystem {
}
func embedFrontend(e *echo.Echo) {
- // Catch-all route to return index.html, this is to prevent 404 when accessing non-root url.
- // See https://stackoverflow.com/questions/27928372/react-router-urls-dont-work-when-refreshing-or-writing-manually
- e.GET("/*", func(c echo.Context) error {
- return c.HTML(http.StatusOK, indexContent)
- })
-
- assetHandler := http.FileServer(getFileSystem())
- e.GET("/assets/*", echo.WrapHandler(assetHandler))
+ // Use echo static middleware to serve the built dist folder
+ // refer: https://github.com/labstack/echo/blob/master/middleware/static.go
+ e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
+ HTML5: true,
+ Filesystem: getFileSystem(),
+ }))
}