summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) {