begin integrating frontend and backend
This commit is contained in:
@@ -6,7 +6,7 @@ import express, { Request, Response } from "express";
|
|||||||
const db = drizzle(process.env.DATABASE_URL!);
|
const db = drizzle(process.env.DATABASE_URL!);
|
||||||
export const articlesRouter = express.Router();
|
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);
|
const resp = await db.select().from(articles);
|
||||||
res.json({ resp });
|
res.json({ resp });
|
||||||
});
|
});
|
||||||
@@ -20,6 +20,15 @@ articlesRouter.get("/getArticle/:articleId", async (req: Request, res: Response)
|
|||||||
res.json({ resp });
|
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) => {
|
articlesRouter.post("/postArticle", async (req: Request, res: Response) => {
|
||||||
const resp = await db
|
const resp = await db
|
||||||
.insert(articles)
|
.insert(articles)
|
||||||
|
|||||||
@@ -5,3 +5,5 @@ import express, { Request, Response } from "express";
|
|||||||
|
|
||||||
const db = drizzle(process.env.DATABASE_URL!);
|
const db = drizzle(process.env.DATABASE_URL!);
|
||||||
export const blocksRouter = express.Router();
|
export const blocksRouter = express.Router();
|
||||||
|
|
||||||
|
// TODO: implement
|
||||||
|
|||||||
@@ -5,3 +5,5 @@ import express, { Request, Response } from "express";
|
|||||||
|
|
||||||
const db = drizzle(process.env.DATABASE_URL!);
|
const db = drizzle(process.env.DATABASE_URL!);
|
||||||
export const imagesRouter = express.Router();
|
export const imagesRouter = express.Router();
|
||||||
|
|
||||||
|
// TODO: Implement
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ createRoot(document.getElementById('root')!).render(
|
|||||||
<Navbar />
|
<Navbar />
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={<Home />} />
|
<Route path="/" element={<Home />} />
|
||||||
<Route path="/article/:articleId" element={<Article />} />
|
<Route path="/article/:slug" element={<Article />} />
|
||||||
<Route path="/articleList" element={<ArticleList />} />
|
<Route path="/articleList" element={<ArticleList />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { useParams } from 'react-router';
|
import { useParams } from 'react-router';
|
||||||
|
// import { useState, useEffect } from 'react';
|
||||||
|
|
||||||
export default function Article() {
|
export default function Article() {
|
||||||
let { articleId } = useParams();
|
let { slug } = useParams();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="article">
|
<div id="article">
|
||||||
<h1>Article: {articleId}</h1>
|
<h1>Article: {slug}</h1>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
+11
-1
@@ -12,4 +12,14 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
})
|
// DEV PROXY
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: 'http://localhost:3000',
|
||||||
|
changeOrigin: true,
|
||||||
|
rewrite: (path) => path.replace(/^\/api/, '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user