From 79c47d47f3dbe5ec41449791a08d837aee1c1299 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Thu, 17 May 2018 20:09:35 +0100 Subject: [PATCH] Implements proper 404s. --- forum.nim | 27 +++++++++++++++++++++++++++ frontend/error.nim | 17 ++++++++++++++++- frontend/forum.nim | 3 +++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/forum.nim b/forum.nim index 27e2a73..0e06a3b 100644 --- a/forum.nim +++ b/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") diff --git a/frontend/error.nim b/frontend/error.nim index a534bde..6a68df4 100644 --- a/frontend/error.nim +++ b/frontend/error.nim @@ -61,4 +61,19 @@ when defined(js): state.error = some(PostError( errorFields: @[], message: "Unknown error occurred." - )) \ No newline at end of file + )) + + 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" \ No newline at end of file diff --git a/frontend/forum.nim b/frontend/forum.nim index c86386c..1ae644e 100644 --- a/frontend/forum.nim +++ b/frontend/forum.nim @@ -71,6 +71,9 @@ proc render(): VNode = ) ) ), + r("/404", + (params: Params) => render404() + ), r("/", (params: Params) => renderThreadList(getLoggedInUser())) ])