From 05fb990b4039366c1738076f52a3d962890633f9 Mon Sep 17 00:00:00 2001 From: LebCit Date: Wed, 26 Jul 2023 21:31:18 +0300 Subject: [PATCH] Fetch posts from routes for updates to take effect --- routes/mainRoute.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/routes/mainRoute.js b/routes/mainRoute.js index c5d22b0..1bddde8 100644 --- a/routes/mainRoute.js +++ b/routes/mainRoute.js @@ -1,7 +1,6 @@ // Internal Functions import { getPosts } from "../functions/blog-doc.js" import { paginator } from "../functions/helpers.js" -const posts = await getPosts() import { initializeApp } from "../functions/initialize.js" const { app, eta } = initializeApp() @@ -10,7 +9,8 @@ import { settings } from "../config/settings.js" // Render, at most, the newest X posts from the list of posts on the Main Route. export const mainRoute = app - .get("/", (c) => { + .get("/", async (c) => { + const posts = await getPosts() const paginatedPosts = paginator(posts, 1, settings.postsPerPage) // Paginate all the posts. Set the first page to 1 and X posts per page. const newestPosts = paginatedPosts.data // Get the first X posts. const lastPage = paginatedPosts.total_pages - 1 // Get the last page number by removing 1 from the total number of pages. @@ -43,7 +43,8 @@ export const mainRoute = app }) // Dynamic route to display the list of posts without the newest X posts - .get("/page/:actualBlogPage", (c) => { + .get("/page/:actualBlogPage", async (c) => { + const posts = await getPosts() const paginatedPosts = paginator(posts, 1, settings.postsPerPage) // Paginate all the posts. Set the first page to 1 and X posts per page. const lastPage = paginatedPosts.total_pages - 1 // Get the last page number by removing 1 from the total number of pages.