-
Can anyone tell me how to get a predefined route first then check the * |
Beta Was this translation helpful? Give feedback.
Answered by
aldas
Jul 22, 2023
Replies: 2 comments 2 replies
-
Could you modify this example to demonstrate your problem: package main
import (
"errors"
"github.com/labstack/echo/v4"
"log"
"net/http"
)
func main() {
e := echo.New()
h := func(c echo.Context) error {
log.Printf("handler is called: %v\n", c.Path())
return c.JSON(http.StatusOK, c.Path())
}
e.GET("*", h)
e.GET("/test", h)
if err := e.Start(":8080"); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
package main
import (
"fmt"
checkerror "server/checkError"
connectdb "server/connectDB"
"server/handler"
"github.com/gofor-little/env"
echo "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
_ "github.com/lib/pq"
)
func main() {
err := env.Load(".env")
if err != nil {
fmt.Println(err.Error())
return
}
userDB := connectdb.UserDB{Name: "Hi", DBP: nil}
err = userDB.ConnectDB()
defer func() {
fmt.Println("DB disconnected")
userDB.CloseDB()
}()
checkerror.Checkerror(err)
e := echo.New()
e.Static("/", "build")
e.Use(middleware.Logger())
e.Use(middleware.AddTrailingSlash())
handler.Apihandler(e, userDB.DBP)
// This will respond to endpoint where it should be static files
e.Get("*",func(c echo.Context) error {
return c.File("index.html")
})
e.Logger.Fatal(e.Start(":1323"))
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your problem is that
and
are actually same route path and when exactly same path is added by
e.Get
it overrides path registered withe.Static
Do I understand correctly that you want to build SPA? where static assets are served from path that are not
handler.Apihandler
paths? If so I suggest usingmiddleware.StaticWithConfig
for that usecase.Try this example: