获取所有帖子API
在index.ts
文件中
//src/index.ts
import { Elysia } from "elysia";
import {getDB} from "./utils/db";
const app = new Elysia();
const con = getDB()
//获取全部帖子
app.get("/posts",async (ctx) => {
try {
const [rows] = await con.query('SELECT * FROM `posts`');
console.log('帖子列表',rows)
return new Response(JSON.stringify(rows));
}catch (error:any) {
return new Response(error.message, { status: 500 });
}
})
app.listen(3000)