Implements proper 404s.
This commit is contained in:
parent
416655764d
commit
79c47d47f3
3 changed files with 46 additions and 1 deletions
27
forum.nim
27
forum.nim
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -71,6 +71,9 @@ proc render(): VNode =
|
|||
)
|
||||
)
|
||||
),
|
||||
r("/404",
|
||||
(params: Params) => render404()
|
||||
),
|
||||
r("/", (params: Params) => renderThreadList(getLoggedInUser()))
|
||||
])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue