2023-05-05 18:59:53 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2023-12-04 19:05:56 -05:00
|
|
|
"fmt"
|
|
|
|
"log"
|
2023-05-05 18:59:53 -04:00
|
|
|
"net/http"
|
|
|
|
|
2023-12-04 19:05:56 -05:00
|
|
|
"git.agecem.com/agecem/babillard/config"
|
|
|
|
"git.agecem.com/agecem/babillard/public"
|
2023-05-05 18:59:53 -04:00
|
|
|
"github.com/labstack/echo/v4"
|
2023-12-04 19:05:56 -05:00
|
|
|
"github.com/labstack/echo/v4/middleware"
|
2023-05-05 18:59:53 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func HandleAPIShow(c echo.Context) error {
|
|
|
|
apispec := `agecem/babillard
|
|
|
|
API Specifications
|
|
|
|
-----
|
|
|
|
'/' | GET | Affiche l'application 'slider'
|
|
|
|
'/api' | GET | Affiche les spécifications API
|
|
|
|
'/api/contenu' | GET | Affiche le nom des fichiers dans 'contenu/'
|
|
|
|
'/api/contenu/{filename}' | GET | Affiche le fichier 'contenu/{filename}'
|
|
|
|
-----`
|
|
|
|
|
|
|
|
return c.String(http.StatusOK, apispec)
|
|
|
|
}
|
2023-12-04 19:05:56 -05:00
|
|
|
|
|
|
|
func RunServer(cfg config.Config) {
|
|
|
|
log.Print("[I] Starting webserver")
|
|
|
|
|
|
|
|
e := echo.New()
|
|
|
|
|
|
|
|
e.Pre(middleware.AddTrailingSlash())
|
|
|
|
|
|
|
|
e.Group("").Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
|
|
|
Root: "/html/",
|
|
|
|
Filesystem: http.FS(public.HTMLFS()),
|
|
|
|
}))
|
|
|
|
e.Group("/public/css").Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
|
|
|
Root: "/css/",
|
|
|
|
Filesystem: http.FS(public.CSSFS()),
|
|
|
|
}))
|
|
|
|
e.Group("/public/js").Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
|
|
|
Root: "/js/",
|
|
|
|
Filesystem: http.FS(public.JSFS()),
|
|
|
|
}))
|
|
|
|
|
|
|
|
groupAPI := e.Group("/api")
|
|
|
|
|
|
|
|
contenuHandler := NewContenuHandler(cfg)
|
|
|
|
|
|
|
|
groupAPI.GET("/", HandleAPIShow)
|
|
|
|
groupAPI.GET("/contenu/", contenuHandler.HandleAPIContenuList)
|
|
|
|
groupAPI.GET("/contenu/:filename/", contenuHandler.HandleAPIContenuFile)
|
|
|
|
|
|
|
|
e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", cfg.ServerPort)))
|
|
|
|
}
|