summaryrefslogtreecommitdiff
path: root/webserver.js
diff options
context:
space:
mode:
Diffstat (limited to 'webserver.js')
-rwxr-xr-xwebserver.js28
1 files changed, 15 insertions, 13 deletions
diff --git a/webserver.js b/webserver.js
index 40b7e28..98a9640 100755
--- a/webserver.js
+++ b/webserver.js
@@ -208,7 +208,9 @@ function anyComponentHidden(fname) {
function requestFile(req, res, path, origpath, options) {
if (options == null) options = {};
fname = cmn.webfilesdir + path;
- console.log("Requesting file " + fname);
+ // Prevent log spam from the crowd all wanting to know who we are
+ if (path != "/well-known/matrix/server") console.log("Requesting file " + fname);
+
if (anyComponentHidden(fname) || !fs.existsSync(fname)) {
res.status(404).send("That file does not exist.");
return;
@@ -250,7 +252,7 @@ function requestFile(req, res, path, origpath, options) {
}
function makeUrlSafe(req, sliceLength) {
- const parsed = url.parse(req.url);
+ const parsed = new URL(req.url, "https://domain");
const part = parsed.pathname.slice(sliceLength);
if (part == "") return "/";
return part.replace(/\/\.+[^\/]*\//g, "/");
@@ -271,28 +273,28 @@ app.get("/", function (req, res) {
// );
});
-app.get(["/f/univq", "/f/univq/*"], cmn.authgen());
+app.get(["/f/univq", "/f/univq/*rest"], cmn.authgen());
-app.get(["/f", "/f/*"], function (req, res) {
+app.get(["/f", "/f/*rest"], function (req, res) {
requestFile(req, res, unescape(makeUrlSafe(req, 2)), req.url);
});
-app.get(["/ff", "/ff/*"], cmn.authgen());
-app.get(["/ff", "/ff/*"], function (req, res) {
+app.get(["/ff", "/ff/*rest"], cmn.authgen());
+app.get(["/ff", "/ff/*rest"], function (req, res) {
requestFile(req, res, unescape(makeUrlSafe(req, 3)), req.url, {listdirs: true});
});
-app.get("/.well-known/matrix/*", function (req, res) {
+app.get("/.well-known/matrix/*rest", function (req, res) {
// 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) {
+app.get("/.well-known/*rest", function (req, res) {
requestFile(req, res, "/well-known" + unescape(makeUrlSafe(req, 12)), req.url);
});
-app.get("/google*.html", function (req, res) {
+/* app.get("/google*rest.html", function (req, res) {
const url = unescape(makeUrlSafe(req, 0));
if (url.match(/^\/google[0-9a-fA-F]*\.html$/)) {
const fname = __dirname + url;
@@ -303,15 +305,15 @@ app.get("/google*.html", function (req, res) {
} else {
res.status(404).send("That file does not exist.");
}
-});
+}); */
["o", "k", "rip", "rip2"].forEach(function (target) {
app.get("/" + target, function (req, res) {
res.sendFile(cmn.webfilesdir + "/" + target + ".html");
});
- app.get("/" + target + "/*", function (req, res) {
- res.set('Content-Type', 'text/html');
- const msg = url.parse(req.url).pathname.slice(target.length + 2);
+ app.get("/" + target + "/*rest", function (req, res) {
+ res.set("Content-Type", "text/html");
+ const msg = new URL(req.url, "https://domain").pathname.slice(target.length + 2);
res.send(
String(fs.readFileSync(cmn.webfilesdir + "/" + target + ".html"))
.replace("<!--MESSAGEMESSAGE-->", cmn.simpleHTMLescape(msg))