mirror of
https://github.com/Fluffy-Bean/TastyBites.git
synced 2024-12-29 10:56:15 +00:00
35 lines
563 B
Go
35 lines
563 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/Fluffy-Bean/TastyBites/front"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/labstack/echo/v4/middleware"
|
|
)
|
|
|
|
type Config struct {
|
|
Host string
|
|
Logging bool
|
|
}
|
|
|
|
func Serve(c Config) {
|
|
r := echo.New()
|
|
|
|
if c.Logging {
|
|
r.Use(middleware.Logger())
|
|
r.Use(middleware.CORS())
|
|
}
|
|
r.Use(middleware.Recover())
|
|
|
|
r.StaticFS("/", front.DistDir)
|
|
|
|
api := r.Group("/api")
|
|
api.GET("/items", func(e echo.Context) error {
|
|
return e.JSON(http.StatusOK, sampleData)
|
|
})
|
|
|
|
r.HideBanner = true
|
|
r.Logger.Fatal(r.Start(c.Host))
|
|
}
|