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())) ])