frontend.go 397 B

123456789101112131415161718192021
  1. package handler
  2. import (
  3. "os"
  4. "path/filepath"
  5. "github.com/labstack/echo/v4"
  6. )
  7. func RegisterFrontend(e *echo.Echo, distPath string) {
  8. e.GET("/*", func(c echo.Context) error {
  9. path := c.Request().URL.Path
  10. filePath := filepath.Join(distPath, path)
  11. if _, err := os.Stat(filePath); err != nil {
  12. return c.File(filepath.Join(distPath, "index.html"))
  13. }
  14. return c.File(filePath)
  15. })
  16. }