Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ services:
- type: bind
source: ./static
target: /app/static
- type: bind
source: ./extlinks/templates/500
target: /app/500
ports:
- "80:80"
depends_on:
Expand Down
8 changes: 8 additions & 0 deletions extlinks/templates/400.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'base.html' %}

{% block content %}
<div class="body">
<h1>400 Bad Request</h1>
<p>Sorry; we don't know what to do with that.</p>
</div>
{% endblock %}
8 changes: 8 additions & 0 deletions extlinks/templates/403.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'base.html' %}

{% block content %}
<div class="body">
<h1>403 Forbidden</h1>
<p>Sorry; you aren't allowed to do that.</p>
</div>
{% endblock %}
8 changes: 8 additions & 0 deletions extlinks/templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'base.html' %}

{% block content %}
<div class="body">
<h1>404 Not Found</h1>
<p>Sorry; we can't find that.</p>
</div>
{% endblock %}
42 changes: 42 additions & 0 deletions extlinks/templates/500/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Wikimedia External Links Tool</title>

<link rel="icon" type="image/png" href="/static/favicon.ico">
<link rel="stylesheet" href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="/static/css/local.css" type="text/css">
</head>

<body>
<nav class="navbar navbar-expand-lg navbar-light shadow-sm">
<a class="navbar-brand" href="/">Wikilink</a>
<div class="navbar-nav">
<a class="nav-item nav-link" href="/programs/">Programs</a>
<a class="nav-item nav-link" href="/organisations/">Organisations</a>
<a class="nav-item nav-link" href="/docs">What is this?</a>
</div>
</nav>

<div class="main-content">
<div class="body">
<h1>500 Internal Server Error</h1>
<p>Sorry; something went wrong.</p>
</div>
</div>

<hr/>

<div class="footer">
A <a href="https://meta.wikimedia.org/wiki/The_Wikipedia_Library">Wikipedia Library</a> project -
<a href="https://github.com/WikipediaLibrary/externallinks">Github</a> -
<a href="https://phabricator.wikimedia.org/project/board/4082/">Phabricator</a> -
<a href="https://meta.wikimedia.org/wiki/Wikilink_tool">Meta</a>
</div>

<script type="text/javascript" src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions extlinks/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.views.generic import TemplateView

from extlinks.healthcheck.urls import urlpatterns as healthcheck_urls
from extlinks.programs.urls import urlpatterns as programs_urls
from extlinks.organisations.urls import urlpatterns as organisations_urls

from .views import Homepage, Documentation

handler500 = "extlinks.views.custom_server_error"

urlpatterns = [
path("admin/", admin.site.urls),
path("", Homepage.as_view(), name="homepage"),
Expand All @@ -31,4 +34,8 @@

urlpatterns += [
path("__debug__/", include(debug_toolbar.urls)),
path("400/", TemplateView.as_view(template_name="400.html")),
path("403/", TemplateView.as_view(template_name="403.html")),
path("404/", TemplateView.as_view(template_name="404.html")),
path("500/", TemplateView.as_view(template_name="500/500.html")),
]
6 changes: 6 additions & 0 deletions extlinks/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.views.decorators.csrf import requires_csrf_token
from django.views.generic import TemplateView
from django.views.defaults import server_error


class Homepage(TemplateView):
Expand All @@ -7,3 +9,7 @@ class Homepage(TemplateView):

class Documentation(TemplateView):
template_name = "documentation.html"

@requires_csrf_token
def custom_server_error(request):
return server_error(request, "500/500.html")
10 changes: 10 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ server {
# checks for static file, if not found proxy to app
try_files $uri @django;
}

location @django {
# Cache
proxy_cache_valid 200 301 302 401 403 404 1d;
Expand All @@ -97,6 +98,7 @@ server {
proxy_redirect off;
proxy_pass http://django_server;
}

location @django-admin-slow {
# https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_send_timeout
proxy_connect_timeout 120s;
Expand All @@ -121,4 +123,12 @@ server {
proxy_redirect off;
proxy_pass http://django_server;
}

proxy_intercept_errors on;
error_page 500 501 502 503 504 505 506 /500.html;

location = /500.html {
root /app/500;
internal;
}
}