Skip to content

Commit

Permalink
chore: add response headers to bust cache for elm and react index.html (
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Hoyoul Kang authored and justin-determined-ai committed Jul 8, 2020
1 parent b309be9 commit cd2e4dd
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions master/internal/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,19 @@ func (m *Master) Run() error {
}

// React WebUI.
reactFiles := [...]fileRoute{
reactIndexFiles := [...]fileRoute{
{"/", "index.html"},
{"/det", "index.html"},
{"/det/*", "index.html"},
}

reactFiles := [...]fileRoute{
{"/security.txt", "security.txt"},
{"/.well-known/security.txt", "security.txt"},
{"/color.less", "color.less"},
{"/manifest.json", "manifest.json"},
{"/favicon.ico", "favicon.ico"},
{"/favicon.ico", "favicon.ico"},
{"/det/*", "index.html"},
}

reactDirs := [...]fileRoute{
Expand All @@ -441,13 +444,29 @@ func (m *Master) Run() error {

// Apply WebUI routes in order.
for _, fileRoute := range elmFiles {
m.echo.File(fileRoute.route, filepath.Join(elmRoot, fileRoute.path))
elmIndexPath := filepath.Join(elmRoot, fileRoute.path)
m.echo.GET(fileRoute.route, func(c echo.Context) error {
c.Response().Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
c.Response().Header().Set("Pragma", "no-cache")
c.Response().Header().Set("Expires", "0")
return c.File(elmIndexPath)
})
}

for _, dirRoute := range elmDirs {
m.echo.Static(dirRoute.route, filepath.Join(elmRoot, dirRoute.path))
}

for _, indexRoute := range reactIndexFiles {
reactIndexPath := filepath.Join(reactRoot, indexRoute.path)
m.echo.GET(indexRoute.route, func(c echo.Context) error {
c.Response().Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
c.Response().Header().Set("Pragma", "no-cache")
c.Response().Header().Set("Expires", "0")
return c.File(reactIndexPath)
})
}

for _, fileRoute := range reactFiles {
m.echo.File(fileRoute.route, filepath.Join(reactRoot, fileRoute.path))
}
Expand Down

0 comments on commit cd2e4dd

Please sign in to comment.