summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-10-17 21:29:31 +0200
committerTom Smeding <tom@tomsmeding.com>2024-10-17 21:29:47 +0200
commit109272df595b8d80c8301d92a734c0a369e11bae (patch)
tree054bb9cf2bce849bba4700fc027e8dc2321f5903
parentd5d25a365a186ca0efd46bcab36a7467de690571 (diff)
Add max-age cache control for matrix well-known files
-rwxr-xr-xwebserver.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/webserver.js b/webserver.js
index 39f2410..a6d9c6f 100755
--- a/webserver.js
+++ b/webserver.js
@@ -198,7 +198,12 @@ function anyComponentHidden(fname) {
// if 'mime' is not null/undefined, it should be the content-type of the file
// options:
-// { mime: "content-type value", listdirs: true/false, cors: true/false }
+// {
+// mime: "content-type value",
+// listdirs: true/false,
+// cors: true/false,
+// cache: "cache-control value"
+// }
// (defaults are null/false)
function requestFile(req, res, path, origpath, options) {
if (options == null) options = {};
@@ -213,6 +218,7 @@ function requestFile(req, res, path, origpath, options) {
const headers = {};
if (options.mime != null) headers["content-type"] = options.mime;
if (options.cors == true) headers["access-control-allow-origin"] = "*";
+ if (options.cache != null) headers["cache-control"] = options.cache;
res.sendFile(fname, {headers});
} else if (stats.isDirectory() && options.listdirs) {
const items = fs
@@ -277,7 +283,9 @@ app.get(["/ff", "/ff/*"], function (req, res) {
});
app.get("/.well-known/matrix/*", function (req, res) {
- requestFile(req, res, "/well-known" + unescape(makeUrlSafe(req, 12)), req.url, {mime: "application/json", cors: true});
+ // Prevent these matrix files from being requested for every trifling event
+ // by giving them an explicit cache lifetime
+ requestFile(req, res, "/well-known" + unescape(makeUrlSafe(req, 12)), req.url, {mime: "application/json", cors: true, cache: "public, max-age=7200"});
});
app.get("/.well-known/*", function (req, res) {