fix: add no cache to static

This commit is contained in:
httpjamesm 2023-02-04 13:14:52 -05:00
parent eee8ec42c5
commit 4d8632e26c
No known key found for this signature in database
2 changed files with 16 additions and 1 deletions

View File

@ -32,7 +32,6 @@ func main() {
r := gin.Default() r := gin.Default()
r.LoadHTMLGlob("templates/*") r.LoadHTMLGlob("templates/*")
r.Static("/static", "./public")
r.Use(gin.Recovery()) r.Use(gin.Recovery())
r.Use(middleware.XssPreventionHeaders()) r.Use(middleware.XssPreventionHeaders())
@ -40,6 +39,8 @@ func main() {
r.Use(middleware.OptionsMiddleware()) r.Use(middleware.OptionsMiddleware())
r.Use(middleware.Ratelimit()) r.Use(middleware.Ratelimit())
r.GET("/static/*filepath", routes.StaticContent)
r.GET("/robots.txt", func(c *gin.Context) { r.GET("/robots.txt", func(c *gin.Context) {
c.String(200, "User-agent: *\nDisallow: /") c.String(200, "User-agent: *\nDisallow: /")
}) })

14
src/routes/static.go Normal file
View File

@ -0,0 +1,14 @@
package routes
import (
"fmt"
"strings"
"github.com/gin-gonic/gin"
)
func StaticContent(c *gin.Context) {
cleanFilePath := strings.ReplaceAll(c.Param("filepath"), "..", "")
c.File(fmt.Sprintf("./public/%s", cleanFilePath))
}