Добавление бэкэнда

This commit is contained in:
2025-11-01 13:10:32 +03:00
parent 55186b3486
commit d6bba525d3
4 changed files with 195 additions and 22 deletions

38
server/main.go Normal file
View File

@@ -0,0 +1,38 @@
package main
import (
// "flag"
// "fmt"
"embed"
"net/http"
"strings"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)
//go:embed static
var staticFiles embed.FS
func SetCustomContentType() gin.HandlerFunc {
return func(c *gin.Context) {
requestPath := c.Request.URL.Path
if strings.HasPrefix(requestPath, "/l/static") {
c.Header("Content-Type", "text/html; charset=UTF-8")
}
c.Next()
}
}
func main() {
embeddedFilesSystem := http.FS(staticFiles)
router := gin.Default()
router.Use(SetCustomContentType())
router.Use(gzip.Gzip(gzip.DefaultCompression))
router.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
router.StaticFS("/l", embeddedFilesSystem)
router.Run(":8080")
}