mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +00:00
Merge pull request #825 from mouse-reeve/misc-server-errors
Misc server errors
This commit is contained in:
commit
47cf1f3b22
7 changed files with 32 additions and 5 deletions
5
bookwyrm/templates/host_meta.xml
Normal file
5
bookwyrm/templates/host_meta.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Link rel="lrdd" template="https://{{ DOMAIN }}/.well-known/webfinger?resource={uri}"/>
|
||||
</XRD>
|
||||
|
5
bookwyrm/templates/robots.txt
Normal file
5
bookwyrm/templates/robots.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
||||
|
||||
User-agent: *
|
||||
Disallow: /static/js/
|
||||
Disallow: /static/css/
|
|
@ -84,6 +84,11 @@ class ViewsHelpers(TestCase):
|
|||
request.headers = {"Accept": "Praise"}
|
||||
self.assertFalse(views.helpers.is_api_request(request))
|
||||
|
||||
def test_is_api_request_no_headers(self, _):
|
||||
""" should it return html or json """
|
||||
request = self.factory.get("/path")
|
||||
self.assertFalse(views.helpers.is_api_request(request))
|
||||
|
||||
def test_is_bookwyrm_request(self, _):
|
||||
""" checks if a request came from a bookwyrm instance """
|
||||
request = self.factory.get("", {"q": "Test Book"})
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.urls import path, re_path
|
||||
|
||||
from django.views.generic.base import TemplateView
|
||||
|
||||
from bookwyrm import settings, views
|
||||
from bookwyrm.utils import regex
|
||||
|
@ -27,12 +27,17 @@ handler404 = "bookwyrm.views.not_found_page"
|
|||
handler500 = "bookwyrm.views.server_error_page"
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path(
|
||||
"robots.txt",
|
||||
TemplateView.as_view(template_name="robots.txt", content_type="text/plain"),
|
||||
),
|
||||
# federation endpoints
|
||||
re_path(r"^inbox/?$", views.Inbox.as_view()),
|
||||
re_path(r"%s/inbox/?$" % local_user_path, views.Inbox.as_view()),
|
||||
re_path(r"%s/outbox/?$" % local_user_path, views.Outbox.as_view()),
|
||||
re_path(r"^.well-known/webfinger/?$", views.webfinger),
|
||||
re_path(r"^.well-known/nodeinfo/?$", views.nodeinfo_pointer),
|
||||
re_path(r"^\.well-known/webfinger/?$", views.webfinger),
|
||||
re_path(r"^\.well-known/nodeinfo/?$", views.nodeinfo_pointer),
|
||||
re_path(r"^\.well-known/host-meta/?$", views.host_meta),
|
||||
re_path(r"^nodeinfo/2\.0/?$", views.nodeinfo),
|
||||
re_path(r"^api/v1/instance/?$", views.instance_info),
|
||||
re_path(r"^api/v1/instance/peers/?$", views.peers),
|
||||
|
|
|
@ -36,4 +36,4 @@ from .tag import Tag, AddTag, RemoveTag
|
|||
from .updates import get_notification_count, get_unread_status_count
|
||||
from .user import User, EditUser, Followers, Following
|
||||
from .user_admin import UserAdmin
|
||||
from .wellknown import webfinger, nodeinfo_pointer, nodeinfo, instance_info, peers
|
||||
from .wellknown import *
|
||||
|
|
|
@ -21,7 +21,7 @@ def get_user_from_username(viewer, username):
|
|||
|
||||
def is_api_request(request):
|
||||
""" check whether a request is asking for html or data """
|
||||
return "json" in request.headers.get("Accept") or request.path[-5:] == ".json"
|
||||
return "json" in request.headers.get("Accept", "") or request.path[-5:] == ".json"
|
||||
|
||||
|
||||
def is_bookwyrm_request(request):
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
from dateutil.relativedelta import relativedelta
|
||||
from django.http import HttpResponseNotFound
|
||||
from django.http import JsonResponse
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils import timezone
|
||||
from django.views.decorators.http import require_GET
|
||||
|
||||
|
@ -118,3 +119,9 @@ def peers(_):
|
|||
""" list of federated servers this instance connects with """
|
||||
names = models.FederatedServer.objects.values_list("server_name", flat=True)
|
||||
return JsonResponse(list(names), safe=False)
|
||||
|
||||
|
||||
@require_GET
|
||||
def host_meta(request):
|
||||
""" meta of the host """
|
||||
return TemplateResponse(request, "host_meta.xml", {"DOMAIN": DOMAIN})
|
||||
|
|
Loading…
Reference in a new issue