Bun入门指南

获取所有帖子API

Preview
  • 获取所有帖子API

获取所有帖子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)

image.png