Initial commit

This commit is contained in:
Arkaprabha Chakraborty
2025-12-01 08:29:49 +05:30
commit 39c61b7790
20 changed files with 4206 additions and 0 deletions

48
internal/server/routes.go Normal file
View File

@@ -0,0 +1,48 @@
package server
import (
"net/http"
"billit/cmd/web"
"github.com/a-h/templ"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func (s *Server) RegisterRoutes() http.Handler {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"https://*", "http://*"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"},
AllowHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
AllowCredentials: true,
MaxAge: 300,
}))
fileServer := http.FileServer(http.FS(web.Files))
e.GET("/assets/*", echo.WrapHandler(fileServer))
e.GET("/web", echo.WrapHandler(templ.Handler(web.HelloForm())))
e.POST("/hello", echo.WrapHandler(http.HandlerFunc(web.HelloWebHandler)))
e.GET("/", s.HelloWorldHandler)
e.GET("/health", s.healthHandler)
return e
}
func (s *Server) HelloWorldHandler(c echo.Context) error {
resp := map[string]string{
"message": "Hello World",
}
return c.JSON(http.StatusOK, resp)
}
func (s *Server) healthHandler(c echo.Context) error {
return c.JSON(http.StatusOK, s.db.Health())
}