-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compute servrer: serve actual cocalc frontend app code.
- also found a cache header bug in hub express server (only impacts cocalc-docker so not a real issue).
- Loading branch information
1 parent
2cd7019
commit 3a334d9
Showing
8 changed files
with
109 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ packages: | |
- "util" | ||
- "terminal" | ||
- "compute" | ||
- "static" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Helper functions for caching static files when using express | ||
*/ | ||
|
||
import ms from "ms"; | ||
|
||
// Used for longterm caching of files. This should be in units of seconds. | ||
const MAX_AGE = Math.round(ms("10 days") / 1000); | ||
const SHORT_AGE = Math.round(ms("10 seconds") / 1000); | ||
|
||
export function cacheShortTerm(res) { | ||
res.setHeader( | ||
"Cache-Control", | ||
`public, max-age=${SHORT_AGE}, must-revalidate`, | ||
); | ||
res.setHeader( | ||
"Expires", | ||
new Date(Date.now().valueOf() + SHORT_AGE).toUTCString(), | ||
); | ||
} | ||
|
||
// Various files such as the webpack static content should be cached long-term, | ||
// and we use this function to set appropriate headers at various points below. | ||
export function cacheLongTerm(res) { | ||
res.setHeader( | ||
"Cache-Control", | ||
`public, max-age=${MAX_AGE}, must-revalidate'`, | ||
); | ||
res.setHeader( | ||
"Expires", | ||
new Date(Date.now().valueOf() + MAX_AGE).toUTCString(), | ||
); | ||
} |
Oops, something went wrong.