Skip to content

Commit 963762a

Browse files
committed
add a 404 page
1 parent 96739f8 commit 963762a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

homu/html/404.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Page not found</title>
6+
<style>
7+
* { font-family: sans-serif; text-align: center; }
8+
h1 { font-size: 20px; }
9+
p { font-size: 15px; }
10+
</style>
11+
</head>
12+
<body>
13+
<h1>Page not found</h1>
14+
<p><a href="/">Go back to the index</a></p>
15+
</body>
16+
</html>
17+

homu/server.py

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
redirect,
2929
abort,
3030
response,
31+
error,
3132
)
3233
from threading import Thread
3334
import sys
@@ -116,6 +117,9 @@ def result(repo_label, pull):
116117

117118
@get('/queue/<repo_label:path>')
118119
def queue(repo_label):
120+
if repo_label not in g.cfg['repo']:
121+
abort(404)
122+
119123
logger = g.logger.getChild('queue')
120124

121125
lazy_debug(logger, lambda: 'repo_label: {}'.format(repo_label))
@@ -197,6 +201,9 @@ def queue(repo_label):
197201

198202
@get('/retry_log/<repo_label:path>')
199203
def retry_log(repo_label):
204+
if repo_label not in g.cfg['repo']:
205+
abort(404)
206+
200207
logger = g.logger.getChild('retry_log')
201208

202209
lazy_debug(logger, lambda: 'repo_label: {}'.format(repo_label))
@@ -983,6 +990,11 @@ def health():
983990
return 'OK'
984991

985992

993+
@error(404)
994+
def not_found(error):
995+
return g.tpls['404'].render()
996+
997+
986998
def redirect_to_canonical_host():
987999
request_url = urllib.parse.urlparse(request.url)
9881000
redirect_url = request_url
@@ -1023,6 +1035,7 @@ def start(cfg, states, queue_handler, repo_cfgs, repos, logger,
10231035
tpls['queue'] = env.get_template('queue.html')
10241036
tpls['build_res'] = env.get_template('build_res.html')
10251037
tpls['retry_log'] = env.get_template('retry_log.html')
1038+
tpls['404'] = env.get_template('404.html')
10261039

10271040
g.cfg = cfg
10281041
g.states = states

0 commit comments

Comments
 (0)