From c5e8faf9ed453708a123d21cb5f6fbdd3cd9db14 Mon Sep 17 00:00:00 2001 From: Roy Dumblauskas Date: Fri, 26 Dec 2025 22:35:53 -0600 Subject: [PATCH] begin integrating frontend and backend --- backend/src/routes/articles.ts | 11 ++++++++++- backend/src/routes/blocks.ts | 2 ++ backend/src/routes/images.ts | 2 ++ frontend/src/main.tsx | 2 +- frontend/src/pages/Article.tsx | 5 +++-- frontend/vite.config.ts | 12 +++++++++++- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/backend/src/routes/articles.ts b/backend/src/routes/articles.ts index f52eb5a..eb28300 100644 --- a/backend/src/routes/articles.ts +++ b/backend/src/routes/articles.ts @@ -6,7 +6,7 @@ import express, { Request, Response } from "express"; const db = drizzle(process.env.DATABASE_URL!); export const articlesRouter = express.Router(); -articlesRouter.get("/getAllArticles", async (req: Request, res: Response) => { +articlesRouter.get("/getAllArticles", async (_, res: Response) => { const resp = await db.select().from(articles); res.json({ resp }); }); @@ -20,6 +20,15 @@ articlesRouter.get("/getArticle/:articleId", async (req: Request, res: Response) res.json({ resp }); }); +articlesRouter.get("/getArticleBySlug/:slug", async (req: Request, res: Response) => { + const { slug } = req.params; + + const resp = await db.select() + .from(articles) + .where(eq(articles.slug, slug)); + res.json({ resp }); +}); + articlesRouter.post("/postArticle", async (req: Request, res: Response) => { const resp = await db .insert(articles) diff --git a/backend/src/routes/blocks.ts b/backend/src/routes/blocks.ts index 144bbff..b0b5b3b 100644 --- a/backend/src/routes/blocks.ts +++ b/backend/src/routes/blocks.ts @@ -5,3 +5,5 @@ import express, { Request, Response } from "express"; const db = drizzle(process.env.DATABASE_URL!); export const blocksRouter = express.Router(); + +// TODO: implement diff --git a/backend/src/routes/images.ts b/backend/src/routes/images.ts index bcf3822..02dd6cf 100644 --- a/backend/src/routes/images.ts +++ b/backend/src/routes/images.ts @@ -5,3 +5,5 @@ import express, { Request, Response } from "express"; const db = drizzle(process.env.DATABASE_URL!); export const imagesRouter = express.Router(); + +// TODO: Implement diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index 9451c44..dd94727 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -13,7 +13,7 @@ createRoot(document.getElementById('root')!).render( } /> - } /> + } /> } /> diff --git a/frontend/src/pages/Article.tsx b/frontend/src/pages/Article.tsx index adf4b69..8e3e297 100644 --- a/frontend/src/pages/Article.tsx +++ b/frontend/src/pages/Article.tsx @@ -1,11 +1,12 @@ import { useParams } from 'react-router'; +// import { useState, useEffect } from 'react'; export default function Article() { - let { articleId } = useParams(); + let { slug } = useParams(); return (
-

Article: {articleId}

+

Article: {slug}

); }; diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index a2b8d5f..df1b552 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -12,4 +12,14 @@ export default defineConfig({ }, }) ], -}) + // DEV PROXY + server: { + proxy: { + '/api': { + target: 'http://localhost:3000', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, '') + } + } + } +});