diff --git a/main.go b/main.go index a0a7682..6ade272 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,6 @@ func main() { r := gin.Default() r.LoadHTMLGlob("templates/*") - r.Static("/static", "./public") r.Use(gin.Recovery()) r.Use(middleware.XssPreventionHeaders()) @@ -40,6 +39,8 @@ func main() { r.Use(middleware.OptionsMiddleware()) r.Use(middleware.Ratelimit()) + r.GET("/static/*filepath", routes.StaticContent) + r.GET("/robots.txt", func(c *gin.Context) { c.String(200, "User-agent: *\nDisallow: /") }) diff --git a/src/routes/static.go b/src/routes/static.go new file mode 100644 index 0000000..b5934a3 --- /dev/null +++ b/src/routes/static.go @@ -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)) +}