Add view to serve matrix server well-known URL

This commit is contained in:
Jake Howard 2022-08-22 14:37:29 +01:00
parent 10b32da3e0
commit 521595a781
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 27 additions and 1 deletions

View file

@ -0,0 +1 @@
{"m.server": "matrix.jakehoward.tech:443"}

View file

@ -49,3 +49,13 @@ class SecurityViewTestCase(TestCase):
response.context["security_txt"], response.context["security_txt"],
"http://testserver/.well-known/security.txt", "http://testserver/.well-known/security.txt",
) )
class MatrixServerViewTestCase(SimpleTestCase):
url = reverse("matrix-server")
def test_accessible(self) -> None:
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response["Content-Type"], "application/json")
self.assertTemplateUsed(response, "matrix-server.json")

View file

@ -54,3 +54,8 @@ class SecurityView(TemplateView):
(timezone.now() + self.expires).replace(microsecond=0).isoformat() (timezone.now() + self.expires).replace(microsecond=0).isoformat()
) )
return context return context
class MatrixServerView(TemplateView):
template_name = "matrix-server.json"
content_type = "application/json"

View file

@ -7,7 +7,12 @@ from wagtail.contrib.sitemaps.views import sitemap
from wagtail.documents import urls as wagtaildocs_urls from wagtail.documents import urls as wagtaildocs_urls
from wagtail.images.views.serve import ServeView from wagtail.images.views.serve import ServeView
from website.common.views import RobotsView, SecurityView, page_not_found from website.common.views import (
MatrixServerView,
RobotsView,
SecurityView,
page_not_found,
)
urlpatterns = [ urlpatterns = [
path("admin/", include(wagtailadmin_urls)), path("admin/", include(wagtailadmin_urls)),
@ -28,6 +33,11 @@ urlpatterns = [
cache_page(SecurityView.expires.total_seconds())(SecurityView.as_view()), cache_page(SecurityView.expires.total_seconds())(SecurityView.as_view()),
name="securitytxt", name="securitytxt",
), ),
path(
".well-known/matrix/server",
cache_page(60 * 60)(MatrixServerView.as_view()),
name="matrix-server",
),
path("404/", page_not_found, name="404"), path("404/", page_not_found, name="404"),
] ]