From 86e411df122cab33b36a6d1337c74492576dcccd Mon Sep 17 00:00:00 2001 From: Disassembler Date: Tue, 14 Aug 2018 15:10:32 +0200 Subject: [PATCH] Return custom 404 page from spotter-manager, related to #269 --- basic/srv/spotter/appmgr/__init__.py | 12 ++++++------ basic/srv/spotter/appmgr/wsgiapp.py | 6 +++++- basic/srv/spotter/templates/404.html | 15 +++++++++++++++ .../spotter/{error.html => templates/502.html} | 4 ++-- 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 basic/srv/spotter/templates/404.html rename basic/srv/spotter/{error.html => templates/502.html} (86%) diff --git a/basic/srv/spotter/appmgr/__init__.py b/basic/srv/spotter/appmgr/__init__.py index 7bce276..97d33aa 100644 --- a/basic/srv/spotter/appmgr/__init__.py +++ b/basic/srv/spotter/appmgr/__init__.py @@ -29,9 +29,9 @@ NGINX_TEMPLATE = '''server {{ proxy_pass http://{ip}:8080; }} - error_page 502 /error.html; - location = /error.html {{ - root /srv/spotter; + error_page 502 /502.html; + location = /502.html {{ + root /srv/spotter/appmgr/templates; }} location = /spotter-ping {{ @@ -69,9 +69,9 @@ server {{ root /srv/spotter; }} - error_page 502 /error.html; - location = /error.html {{ - root /srv/spotter; + error_page 502 /502.html; + location = /502.html {{ + root /srv/spotter/appmgr/templates; }} location = /spotter-ping {{ diff --git a/basic/srv/spotter/appmgr/wsgiapp.py b/basic/srv/spotter/appmgr/wsgiapp.py index 7645757..5cb642a 100644 --- a/basic/srv/spotter/appmgr/wsgiapp.py +++ b/basic/srv/spotter/appmgr/wsgiapp.py @@ -3,7 +3,7 @@ import json import os -from werkzeug.exceptions import BadRequest, HTTPException +from werkzeug.exceptions import BadRequest, HTTPException, NotFound from werkzeug.routing import Map, Rule from werkzeug.utils import redirect from werkzeug.wrappers import Request, Response @@ -81,6 +81,10 @@ class WSGIApp(object): try: endpoint, values = adapter.match() return getattr(self, endpoint)(request, **values) + except NotFound as e: + response = self.render_template('404.html') + response.status_code = 404 + return response except HTTPException as e: return e diff --git a/basic/srv/spotter/templates/404.html b/basic/srv/spotter/templates/404.html new file mode 100644 index 0000000..364c4d6 --- /dev/null +++ b/basic/srv/spotter/templates/404.html @@ -0,0 +1,15 @@ + + + + + + + + + Chyba 404 + + +

Stránka nebyla nalezena

+

Stránka, kterou se pokoušíte zobrazit, nebyla na serveru nalezena. Zkontrolujte prosím URL v adresním řádku nebo se vraťte zpět na úvodní stránku.

+ + diff --git a/basic/srv/spotter/error.html b/basic/srv/spotter/templates/502.html similarity index 86% rename from basic/srv/spotter/error.html rename to basic/srv/spotter/templates/502.html index 692d977..7c17d66 100644 --- a/basic/srv/spotter/error.html +++ b/basic/srv/spotter/templates/502.html @@ -6,10 +6,10 @@ - Chyba + Chyba 502 -

Chyba spojení

+

Chyba spojení s aplikací

Aplikace ke které se pokoušíte připojit není dostupná. Nejspíše byla vypnuta správcem serveru.