feat: cache static files (#2715)

pull/2595/head
BoYanZh 2022-12-15 17:48:29 +08:00 committed by GitHub
parent 6f4b1ba4b3
commit e58ca686e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -65,6 +65,13 @@ func UpdateIndex() {
func Static(r *gin.Engine) {
InitIndex()
folders := []string{"assets", "images", "streamer"}
r.Use(func(c *gin.Context) {
for i := range folders {
if strings.HasPrefix(c.Request.RequestURI, fmt.Sprintf("/%s/", folders[i])) {
c.Header("Cache-Control", "max-age=86400")
}
}
})
for i, folder := range folders {
folder = "dist/" + folder
sub, err := fs.Sub(public.Public, folder)