Skip to content

Commit 55d9291

Browse files
authored
Fix cache-control header for 404 requests (#1169)
1 parent 369126a commit 55d9291

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

server/router.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ func esmRouter(db Database, buildStorage storage.Storage, logger *log.Logger) re
14671467
case output := <-ch:
14681468
if output.err != nil {
14691469
if output.err.Error() == "types not found" {
1470-
ctx.SetHeader("Cache-Control", ccImmutable)
1470+
ctx.SetHeader("Cache-Control", fmt.Sprintf("public, max-age=%d", config.NpmQueryCacheTTL))
14711471
return rex.Status(404, "Types Not Found")
14721472
}
14731473
return rex.Status(500, "Failed to build types: "+output.err.Error())
@@ -1583,11 +1583,7 @@ func esmRouter(db Database, buildStorage storage.Storage, logger *log.Logger) re
15831583
if output.err != nil {
15841584
msg := output.err.Error()
15851585
if msg == "could not resolve build entry" || strings.HasSuffix(msg, " not found") || strings.Contains(msg, "is not exported from package") || strings.Contains(msg, "no such file or directory") {
1586-
if strings.HasPrefix(msg, "version ") && strings.HasSuffix(msg, " not found") {
1587-
ctx.SetHeader("Cache-Control", fmt.Sprintf("public, max-age=%d", config.NpmQueryCacheTTL))
1588-
} else {
1589-
ctx.SetHeader("Cache-Control", ccImmutable)
1590-
}
1586+
ctx.SetHeader("Cache-Control", fmt.Sprintf("public, max-age=%d", config.NpmQueryCacheTTL))
15911587
return rex.Status(404, msg)
15921588
}
15931589
return rex.Status(500, msg)

0 commit comments

Comments
 (0)