diff --git a/apps/api/app/api/[...route]/route.ts b/apps/api/app/api/[...route]/route.ts deleted file mode 100644 index 43f7a46..0000000 --- a/apps/api/app/api/[...route]/route.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { prisma } from "@repo/db"; -import { Hono } from "hono"; -import { handle } from "hono/vercel"; - -export const runtime = "nodejs"; - -export const app = new Hono().basePath("/api"); - -app - .get("/hello", async (c) => { - const test = await prisma.user.findMany(); - return c.json({ - test, - }); - }) - .patch(async (c) => { - const name = await c.req.json(); - const test = await prisma.user.update({ - where: { - id: "123", - }, - data: { - name: name.name, - }, - }); - return c.json({ - test, - }); - }) - .delete(async (c) => { - const test = await prisma.user.delete({ - where: { - id: "2", - }, - }); - return c.json({ - test, - }); - }) - .post(async (c) => { - const body = await c.req.json(); - console.log(body); - const test = await prisma.user.create({ - data: body, - }); - return c.json({ - test, - }); - }); - -app.get("/health", async (c) => { - return c.json({ - message: "i am alive", - status: 200, - }); -}); - -export const GET = handle(app); -export const POST = handle(app); -export const PATCH = handle(app); -export const DELETE = handle(app); diff --git a/apps/api/app/api/[[...route]]/route.ts b/apps/api/app/api/[[...route]]/route.ts new file mode 100644 index 0000000..e999f69 --- /dev/null +++ b/apps/api/app/api/[[...route]]/route.ts @@ -0,0 +1,61 @@ +import { prisma } from "@repo/db"; +import { Hono } from "hono"; +import { handle } from "hono/vercel"; + + +export const runtime = "nodejs"; + +export const app = new Hono().basePath("/api"); + +app.get("/hello",async(c) => { + const test = await prisma.user.findMany() + return c.json({ + test + }); +}) +.patch( async(c) => { + const name = await c.req.json() + const test = await prisma.user.update({ + where: { + id: "123", + }, + data: { + name:name.name + } + }) + return c.json({ + test + }); +}) +.delete( async(c) => { + const test = await prisma.user.delete({ + where: { + id: "2", + } + }) + return c.json({ + test + }); +}) +.post(async(c) => { + const body = await c.req.json() + console.log(body) + const test = await prisma.user.create({ + data: body + }) + return c.json({ + test + }); +}); + +app.get("/health", async(c) => { + return c.json({ + message:"i am alive", + status:200 + }); +}); + +export const GET = handle(app); +export const POST = handle(app); +export const PATCH = handle(app); +export const DELETE = handle(app); \ No newline at end of file diff --git a/apps/api/tests/hello.test.ts b/apps/api/tests/hello.test.ts index 4b202d0..26749b7 100644 --- a/apps/api/tests/hello.test.ts +++ b/apps/api/tests/hello.test.ts @@ -1,13 +1,13 @@ import { describe, it, expect, test } from "vitest"; import request from "supertest"; -import { app } from "../app/api/[...route]/route"; +import { app } from "../app/api/[[...route]]/route"; describe("Example", () => { test("GET /health", async () => { const res = await app.request("/api/health"); expect(res.status).toBe(200); expect(await res.text()).toBe( - JSON.stringify({ message: "i am alive", status: 200 }), + JSON.stringify({ message: "i am alive", status: 200 }) ); }); });