Добавление бэкэнда
This commit is contained in:
38
server/main.go
Normal file
38
server/main.go
Normal 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")
|
||||
}
|
||||
Reference in New Issue
Block a user