Implements proper 404s.

This commit is contained in:
Dominik Picheta 2018-05-17 20:09:35 +01:00
commit 79c47d47f3
3 changed files with 46 additions and 1 deletions

View file

@ -1503,6 +1503,33 @@ routes:
except ForumError as exc:
resp Http400, $(%exc.data), "application/json"
get "/t/@id":
cond "id" in request.params
const threadsQuery =
sql"""select id from thread where id = ? and isDeleted = 0;"""
let value = getValue(db, threadsQuery, @"id")
if value == @"id":
pass
else:
redirect uri("/404")
get "/profile/@username":
cond "username" in request.params
const threadsQuery =
sql"""select name from person where name = ? and isDeleted = 0;"""
let value = getValue(db, threadsQuery, @"username")
if value == @"username":
pass
else:
redirect uri("/404")
get "/404":
resp Http404, readFile("frontend/karax.html")
get re"/(.+)?":
resp readFile("frontend/karax.html")

View file

@ -61,4 +61,19 @@ when defined(js):
state.error = some(PostError(
errorFields: @[],
message: "Unknown error occurred."
))
))
proc render404*(): VNode =
result = buildHtml():
tdiv(class="empty error"):
tdiv(class="empty icon"):
italic(class="fas fa-bug fa-5x")
p(class="empty-title h5"):
text "404 Not Found"
p(class="empty-subtitle"):
text "Cannot find what you are looking for, it might have been " &
"deleted. Sorry!"
tdiv(class="empty-action"):
a(href="/", onClick=anchorCB):
button(class="btn btn-primary"):
text "Go back home"

View file

@ -71,6 +71,9 @@ proc render(): VNode =
)
)
),
r("/404",
(params: Params) => render404()
),
r("/", (params: Params) => renderThreadList(getLoggedInUser()))
])