Skip to content

Commit

Permalink
♻️ (web): Get data directly from DB
Browse files Browse the repository at this point in the history
  • Loading branch information
toridoriv committed Oct 2, 2023
1 parent 0369751 commit aa689df
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions server/web/views/home.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { init } from "@endpoint";
import { Fanfictions, z } from "@deps";
import { fetchFromApi } from "@utils";

const home = init({
path: "/",
Expand All @@ -14,11 +13,9 @@ const home = init({

export default home.registerHandler(
async function mainHandler(this: typeof home, _req, res, _next) {
const response = await fetchFromApi<Fanfictions.Fanfiction[]>(
"/api/fanfictions",
);
const fanfictions = response.data;
const fanfictions = await res.app.db.fanfictions.find({}).limit(5)
.toArray();

return this.renderOk(res, { fanfictions: fanfictions || [] });
return this.renderOk(res, { fanfictions });
},
);

0 comments on commit aa689df

Please sign in to comment.