From bbc330284b1ca0336de87aa1362bd0824ca99175 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Fri, 15 Dec 2023 20:34:59 +0200
Subject: [PATCH] Web proxy: Matrix well-known info.

---
 Compose/web-proxy/ns4/conf.d/nehe.sr.conf     |  2 ++
 Compose/web-proxy/ns4/conf.d/nehes.co.conf    |  2 ++
 Compose/web-proxy/ns4/conf.d/shore.co.il.conf |  3 ++-
 .../ns4/snippets/matrix-well-known.conf       | 21 +++++++++++++++++++
 4 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 Compose/web-proxy/ns4/snippets/matrix-well-known.conf

diff --git a/Compose/web-proxy/ns4/conf.d/nehe.sr.conf b/Compose/web-proxy/ns4/conf.d/nehe.sr.conf
index 289bb2a..2b23fc1 100644
--- a/Compose/web-proxy/ns4/conf.d/nehe.sr.conf
+++ b/Compose/web-proxy/ns4/conf.d/nehe.sr.conf
@@ -6,6 +6,7 @@ server {
     include     snippets/robots-allow-all.conf;
     include     snippets/ads-txt.conf;
     include     snippets/security-txt.conf;
+    include     snippets/matrix-well-known.conf;
     include     snippets/www-acme-challenge.conf;
     include     snippets/redirect-www.conf;
 }
@@ -19,6 +20,7 @@ server {
     include     snippets/security-txt.conf;
     include     snippets/ssl-legacy.conf;
     include     snippets/nextcloud-well-known.conf;
+    include     snippets/matrix-well-known.conf;
     include     snippets/activesync.conf;
     include     snippets/redirect-www.conf;
 }
diff --git a/Compose/web-proxy/ns4/conf.d/nehes.co.conf b/Compose/web-proxy/ns4/conf.d/nehes.co.conf
index db751dd..8cb6ecc 100644
--- a/Compose/web-proxy/ns4/conf.d/nehes.co.conf
+++ b/Compose/web-proxy/ns4/conf.d/nehes.co.conf
@@ -6,6 +6,7 @@ server {
     include     snippets/robots-allow-all.conf;
     include     snippets/ads-txt.conf;
     include     snippets/security-txt.conf;
+    include     snippets/matrix-well-known.conf;
     include     snippets/www-acme-challenge.conf;
     include     snippets/redirect-www.conf;
 }
@@ -18,6 +19,7 @@ server {
     include     snippets/ads-txt.conf;
     include     snippets/security-txt.conf;
     include     snippets/ssl-legacy.conf;
+    include     snippets/matrix-well-known.conf;
     include     snippets/nextcloud-well-known.conf;
     include     snippets/activesync.conf;
     include     snippets/redirect-www.conf;
diff --git a/Compose/web-proxy/ns4/conf.d/shore.co.il.conf b/Compose/web-proxy/ns4/conf.d/shore.co.il.conf
index 24d3c4b..af5858a 100644
--- a/Compose/web-proxy/ns4/conf.d/shore.co.il.conf
+++ b/Compose/web-proxy/ns4/conf.d/shore.co.il.conf
@@ -8,6 +8,7 @@ server {
     include     snippets/robots-allow-all.conf;
     include     snippets/ads-txt.conf;
     include     snippets/security-txt.conf;
+    include     snippets/matrix-well-known.conf;
     include     snippets/www-acme-challenge.conf;
     include     snippets/redirect-www.conf;
 
@@ -23,9 +24,9 @@ server {
     include     snippets/security-txt.conf;
     include     snippets/ssl-legacy.conf;
     include     snippets/nextcloud-well-known.conf;
+    include     snippets/matrix-well-known.conf;
     include     snippets/activesync.conf;
     include     snippets/redirect-www.conf;
-    include     snippets/matrix-well-known.conf;
 
     location = /        { return 301 https://www.shore.co.il/blog/; }
 }
diff --git a/Compose/web-proxy/ns4/snippets/matrix-well-known.conf b/Compose/web-proxy/ns4/snippets/matrix-well-known.conf
new file mode 100644
index 0000000..beb47c9
--- /dev/null
+++ b/Compose/web-proxy/ns4/snippets/matrix-well-known.conf
@@ -0,0 +1,21 @@
+# vim: ft=nginx
+location = /.well-known/matrix/server {
+    if ($scheme = http) {
+        return 301 https://$host$request_uri;
+    }
+    if ($scheme = https) {
+        add_header Content-Type "application/json; charset=utf-8";
+        return 200 "{\"m.server\": \"matrix.shore.co.il:443\"}";
+    }
+}
+
+location = /.well-known/matrix/client {
+    if ($scheme = http) {
+        return 301 https://$host$request_uri;
+    }
+    if ($scheme = https) {
+        add_header Content-Type "application/json; charset=utf-8";
+        add_header Access-Control-Allow-Origin *;
+        return 200 "{\"m.homeserver\": { \"base_url\": \"https://matrix.shore.co.il\" } }";
+    }
+}
-- 
GitLab