Skip to content

Commit 21cd87d

Browse files
feat: Cache-Control for files
1 parent 0965b9c commit 21cd87d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

web/controllers/controllers.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/ItsNotGoodName/smtpbridge/internal/models"
1010
"github.com/ItsNotGoodName/smtpbridge/internal/procs"
1111
"github.com/ItsNotGoodName/smtpbridge/pkg/pagination"
12+
"github.com/ItsNotGoodName/smtpbridge/web"
1213
"github.com/ItsNotGoodName/smtpbridge/web/helpers"
1314
"github.com/gofiber/fiber/v2"
1415
"github.com/gofiber/fiber/v2/middleware/filesystem"
@@ -38,7 +39,8 @@ func Index(retentionPolicy models.RetentionPolicy) func(c *fiber.Ctx, cc *core.C
3839

3940
func Files(app core.App) fiber.Handler {
4041
return filesystem.New(filesystem.Config{
41-
Root: http.FS(app.File.FS),
42+
Root: http.FS(app.File.FS),
43+
MaxAge: web.MaxAge,
4244
})
4345
}
4446

web/web_dev.go

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515

1616
var Development = true
1717

18+
const MaxAge = 0
19+
1820
var pathAssets string
1921
var pathViews string
2022

web/web_not_dev.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414

1515
var Development = false
1616

17+
const MaxAge = 3600
18+
1719
//go:embed dist
1820
var assets embed.FS
1921

@@ -27,7 +29,8 @@ func AssetsFS() fs.FS {
2729

2830
func UseAssets(app *fiber.App) {
2931
app.Use(filesystem.New(filesystem.Config{
30-
Root: http.FS(AssetsFS()),
32+
Root: http.FS(AssetsFS()),
33+
MaxAge: MaxAge,
3134
}))
3235
}
3336

0 commit comments

Comments
 (0)