Skip to content

Commit

Permalink
refactor api
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfdivyansh committed Nov 20, 2024
1 parent a3cb0e0 commit 1521c35
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 69 deletions.
10 changes: 10 additions & 0 deletions apps/api/app/api/[[...route]]/health.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Hono } from "hono";
const app = new Hono();
app.get("/", async (c) => {
return c.json({
message: "i am alive",
status: 200,
});
});

export default app
47 changes: 0 additions & 47 deletions apps/api/app/api/[[...route]]/hello.ts

This file was deleted.

26 changes: 4 additions & 22 deletions apps/api/app/api/[[...route]]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { Hono } from "hono";
import { auth as Auth } from "@repo/auth";
import { cors } from "hono/cors";
import mail from "./mail";
import hello from "./hello";
import hello from "./test";
import session from "./session";
import auth from "./auth";
import status from "./status";
import health from "./health";

const allowedOrigins = [
"http://localhost:3003",
Expand Down Expand Up @@ -34,29 +35,10 @@ app.use(
credentials: true,
}),
);
app.use("*", async (c, next) => {
const session = await Auth.api.getSession({ headers: c.req.raw.headers });

if (!session) {
c.set("user", null);
c.set("session", null);
return next();
}

c.set("user", session.user);
c.set("session", session.session);
return next();
});

app.get("/health", async (c) => {
return c.json({
message: "i am alive",
status: 200,
});
});

app.route("/health", health);
app.route("/session", session);
app.route("/hello", hello);
app.route("/test", hello);
app.route("/mail", mail);
app.route("/auth", auth);
app.route("/status", status);
Expand Down
14 changes: 14 additions & 0 deletions apps/api/app/api/[[...route]]/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Hono } from "hono";
import { prisma } from "@repo/db";

const app = new Hono();

app
.get("/", async (c) => {
const user = await prisma.user.findMany();
return c.json({
user,
});
})

export default app;

0 comments on commit 1521c35

Please sign in to comment.