From b69185ee9e2d61af761f39585a64d8bae3934274 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Mon, 9 Aug 2021 18:16:27 +0800 Subject: [PATCH] control search engine visibility --- index.html | 1 - public/robots.txt | 3 --- server/server.js | 16 +++++++++++++--- src/pages/Settings.vue | 6 +++--- 4 files changed, 16 insertions(+), 10 deletions(-) delete mode 100644 public/robots.txt diff --git a/index.html b/index.html index 901fbf0ea..2a4d4e5d9 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,6 @@ - diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index e9e57dc4d..000000000 --- a/public/robots.txt +++ /dev/null @@ -1,3 +0,0 @@ -# https://www.robotstxt.org/robotstxt.html -User-agent: * -Disallow: diff --git a/server/server.js b/server/server.js index 845310e2d..62fe15d15 100644 --- a/server/server.js +++ b/server/server.js @@ -88,16 +88,26 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); // Normal Router here - app.use("/", express.static("dist")); + // Robots.txt + app.get("/robots.txt", async (_request, response) => { + let txt = "User-agent: *\nDisallow:"; + if (! await setting("searchEngineIndex")) { + txt += " /"; + } + response.setHeader("Content-Type", "text/plain"); + response.send(txt); + }); // Basic Auth Router here // Prometheus API metrics /metrics // With Basic Auth using the first user's username/password - app.get("/metrics", basicAuth, prometheusAPIMetrics()) + app.get("/metrics", basicAuth, prometheusAPIMetrics()); + + app.use("/", express.static("dist")); // Universal Route Handler, must be at the end - app.get("*", function(_request, response) { + app.get("*", async (_request, response) => { response.send(indexHTML); }); diff --git a/src/pages/Settings.vue b/src/pages/Settings.vue index 164c169b0..56d307d9b 100644 --- a/src/pages/Settings.vue +++ b/src/pages/Settings.vue @@ -42,13 +42,13 @@
- +
- + @@ -185,7 +185,7 @@ export default { saveGeneral() { localStorage.timezone = this.$root.userTimezone; - toast.success("Saved.") + this.saveSettings(); }, savePassword() {