From 91619bf224daff5be2da2f03371630e6ac726810 Mon Sep 17 00:00:00 2001 From: Divyanshgupta030 <145568562+Divyanshgupta030@users.noreply.github.com> Date: Thu, 21 Nov 2024 20:40:56 +0530 Subject: [PATCH 1/3] add dynamic import --- apps/api/app/api/[[...route]]/health.ts | 2 +- apps/api/app/api/[[...route]]/mail.ts | 3 ++- apps/api/app/api/[[...route]]/route.ts | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/api/app/api/[[...route]]/health.ts b/apps/api/app/api/[[...route]]/health.ts index 1c06062..1c0abf6 100644 --- a/apps/api/app/api/[[...route]]/health.ts +++ b/apps/api/app/api/[[...route]]/health.ts @@ -1,6 +1,6 @@ import { Hono } from "hono"; const app = new Hono(); -app.get("/", async (c) => { +app.get("/", (c) => { return c.json({ message: "i am alive", status: 200, diff --git a/apps/api/app/api/[[...route]]/mail.ts b/apps/api/app/api/[[...route]]/mail.ts index 1db0248..78f2fcf 100644 --- a/apps/api/app/api/[[...route]]/mail.ts +++ b/apps/api/app/api/[[...route]]/mail.ts @@ -1,5 +1,4 @@ import { Hono } from "hono"; -import { sendBatchEmail, sendEmail } from "@repo/mail"; import { mailBatchSchema, mailSchema } from "@repo/types"; import { zValidator } from "@hono/zod-validator"; @@ -8,6 +7,7 @@ const app = new Hono(); app .post("/send", zValidator("json", mailSchema), async (c) => { const { email, subject } = c.req.valid("json"); + const { sendEmail } = await import("@repo/mail"); const { data, error } = await sendEmail(email, subject); if (error) { return c.json( @@ -35,6 +35,7 @@ app app .post("/send-batch", zValidator("json", mailBatchSchema), async (c) => { const { emails, subject } = c.req.valid("json"); + const { sendBatchEmail } = await import("@repo/mail"); const { data, error } = await sendBatchEmail(emails, subject); if (error) { return c.json( diff --git a/apps/api/app/api/[[...route]]/route.ts b/apps/api/app/api/[[...route]]/route.ts index fe10c89..c72510f 100644 --- a/apps/api/app/api/[[...route]]/route.ts +++ b/apps/api/app/api/[[...route]]/route.ts @@ -3,7 +3,7 @@ import { Hono } from "hono"; import { auth as Auth } from "@repo/auth"; import { cors } from "hono/cors"; import mail from "./mail"; -import hello from "./test"; +import test from "./test"; import session from "./session"; import auth from "./auth"; import status from "./status"; @@ -38,7 +38,7 @@ app.use( app.route("/health", health); app.route("/session", session); -app.route("/test", hello); +app.route("/hello", test); app.route("/mail", mail); app.route("/auth", auth); app.route("/status", status); From 8706a1f0c66f4ef8d0be69d01a3bf24185cb58e3 Mon Sep 17 00:00:00 2001 From: Divyanshgupta030 <145568562+Divyanshgupta030@users.noreply.github.com> Date: Thu, 21 Nov 2024 21:05:46 +0530 Subject: [PATCH 2/3] add typesafe api --- apps/api/app/api/[[...route]]/auth.ts | 5 ++--- apps/api/app/api/[[...route]]/health.ts | 4 ++-- apps/api/app/api/[[...route]]/mail.ts | 8 ++------ apps/api/app/api/[[...route]]/route.ts | 2 +- apps/api/app/api/[[...route]]/session.ts | 10 ++++------ apps/api/app/api/[[...route]]/status.ts | 15 ++++++--------- apps/api/app/api/[[...route]]/test.ts | 5 ++--- 7 files changed, 19 insertions(+), 30 deletions(-) diff --git a/apps/api/app/api/[[...route]]/auth.ts b/apps/api/app/api/[[...route]]/auth.ts index b1f1886..5876817 100644 --- a/apps/api/app/api/[[...route]]/auth.ts +++ b/apps/api/app/api/[[...route]]/auth.ts @@ -1,9 +1,8 @@ import { auth } from "@repo/auth"; import { Hono } from "hono"; -const app = new Hono(); - -app.on(["POST", "GET"], "/**", (c) => { +const app = new Hono() +.on(["POST", "GET"], "/**", (c) => { return auth.handler(c.req.raw); }); diff --git a/apps/api/app/api/[[...route]]/health.ts b/apps/api/app/api/[[...route]]/health.ts index 3cde7c3..6c24021 100644 --- a/apps/api/app/api/[[...route]]/health.ts +++ b/apps/api/app/api/[[...route]]/health.ts @@ -1,6 +1,6 @@ import { Hono } from "hono"; -const app = new Hono(); -app.get("/", (c) => { +const app = new Hono() +.get("/", (c) => { return c.json({ message: "i am alive", status: 200, diff --git a/apps/api/app/api/[[...route]]/mail.ts b/apps/api/app/api/[[...route]]/mail.ts index 78f2fcf..f2c5c78 100644 --- a/apps/api/app/api/[[...route]]/mail.ts +++ b/apps/api/app/api/[[...route]]/mail.ts @@ -2,9 +2,7 @@ import { Hono } from "hono"; import { mailBatchSchema, mailSchema } from "@repo/types"; import { zValidator } from "@hono/zod-validator"; -const app = new Hono(); - -app +const app = new Hono() .post("/send", zValidator("json", mailSchema), async (c) => { const { email, subject } = c.req.valid("json"); const { sendEmail } = await import("@repo/mail"); @@ -30,9 +28,7 @@ app message: "mail api is alive", status: 200, }); - }); - -app + }) .post("/send-batch", zValidator("json", mailBatchSchema), async (c) => { const { emails, subject } = c.req.valid("json"); const { sendBatchEmail } = await import("@repo/mail"); diff --git a/apps/api/app/api/[[...route]]/route.ts b/apps/api/app/api/[[...route]]/route.ts index c72510f..3fe2b77 100644 --- a/apps/api/app/api/[[...route]]/route.ts +++ b/apps/api/app/api/[[...route]]/route.ts @@ -38,7 +38,7 @@ app.use( app.route("/health", health); app.route("/session", session); -app.route("/hello", test); +app.route("/test", test); app.route("/mail", mail); app.route("/auth", auth); app.route("/status", status); diff --git a/apps/api/app/api/[[...route]]/session.ts b/apps/api/app/api/[[...route]]/session.ts index f8c1ca2..408aa55 100644 --- a/apps/api/app/api/[[...route]]/session.ts +++ b/apps/api/app/api/[[...route]]/session.ts @@ -1,9 +1,8 @@ import { Hono } from "hono"; import { auth } from "@repo/auth"; -const app = new Hono(); - -app.get("/", async (c) => { +const app = new Hono() +.get("/", async (c) => { const session = await auth.api.getSession({ headers: c.req.raw.headers }); if (!session) return c.json({ message: "no session found" }, 401); @@ -11,9 +10,8 @@ app.get("/", async (c) => { return c.json({ session, }); -}); - -app.get("/all", async (c) => { +}) +.get("/all", async (c) => { const res = await auth.api.listDeviceSessions({ headers: c.req.raw.headers, }); diff --git a/apps/api/app/api/[[...route]]/status.ts b/apps/api/app/api/[[...route]]/status.ts index 3827e26..e6b88ee 100644 --- a/apps/api/app/api/[[...route]]/status.ts +++ b/apps/api/app/api/[[...route]]/status.ts @@ -1,25 +1,22 @@ import { Hono } from "hono"; import { cache } from "@repo/cache"; -const app = new Hono(); - -app.get("/", async (c) => { +const app = new Hono() +.get("/", async (c) => { const dbStatus = await cache.lrange("db-latency:history", 0, -1); const siteStatus = await cache.lrange("site-latency:history", 0, -1); return c.json({ dbStatus, siteStatus, }); -}); - -app.get("/db", async (c) => { +}) +.get("/db", async (c) => { const dbStatus = await cache.lrange("db-latency:history", 0, -1); return c.json({ dbStatus, }); -}); - -app.get("/site", async (c) => { +}) +.get("/site", async (c) => { const siteStatus = await cache.lrange("site-latency:history", 0, -1); return c.json({ siteStatus, diff --git a/apps/api/app/api/[[...route]]/test.ts b/apps/api/app/api/[[...route]]/test.ts index 8332e20..047d723 100644 --- a/apps/api/app/api/[[...route]]/test.ts +++ b/apps/api/app/api/[[...route]]/test.ts @@ -1,9 +1,8 @@ import { Hono } from "hono"; import { prisma } from "@repo/db"; -const app = new Hono(); - -app.get("/", async (c) => { +const app = new Hono() +.get("/", async (c) => { const user = await prisma.user.findMany(); return c.json({ user, From 90e17b9abd4dbfc316834c7d04bece8995ccf9f9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 21 Nov 2024 15:36:35 +0000 Subject: [PATCH 3/3] chore: format code with Prettier --- apps/api/app/api/[[...route]]/auth.ts | 3 +- apps/api/app/api/[[...route]]/health.ts | 3 +- apps/api/app/api/[[...route]]/session.ts | 24 +++++++-------- apps/api/app/api/[[...route]]/status.ts | 38 ++++++++++++------------ apps/api/app/api/[[...route]]/test.ts | 3 +- 5 files changed, 34 insertions(+), 37 deletions(-) diff --git a/apps/api/app/api/[[...route]]/auth.ts b/apps/api/app/api/[[...route]]/auth.ts index 5876817..a965ca3 100644 --- a/apps/api/app/api/[[...route]]/auth.ts +++ b/apps/api/app/api/[[...route]]/auth.ts @@ -1,8 +1,7 @@ import { auth } from "@repo/auth"; import { Hono } from "hono"; -const app = new Hono() -.on(["POST", "GET"], "/**", (c) => { +const app = new Hono().on(["POST", "GET"], "/**", (c) => { return auth.handler(c.req.raw); }); diff --git a/apps/api/app/api/[[...route]]/health.ts b/apps/api/app/api/[[...route]]/health.ts index 6c24021..9a23dd3 100644 --- a/apps/api/app/api/[[...route]]/health.ts +++ b/apps/api/app/api/[[...route]]/health.ts @@ -1,6 +1,5 @@ import { Hono } from "hono"; -const app = new Hono() -.get("/", (c) => { +const app = new Hono().get("/", (c) => { return c.json({ message: "i am alive", status: 200, diff --git a/apps/api/app/api/[[...route]]/session.ts b/apps/api/app/api/[[...route]]/session.ts index 408aa55..3472b80 100644 --- a/apps/api/app/api/[[...route]]/session.ts +++ b/apps/api/app/api/[[...route]]/session.ts @@ -2,20 +2,20 @@ import { Hono } from "hono"; import { auth } from "@repo/auth"; const app = new Hono() -.get("/", async (c) => { - const session = await auth.api.getSession({ headers: c.req.raw.headers }); + .get("/", async (c) => { + const session = await auth.api.getSession({ headers: c.req.raw.headers }); - if (!session) return c.json({ message: "no session found" }, 401); + if (!session) return c.json({ message: "no session found" }, 401); - return c.json({ - session, + return c.json({ + session, + }); + }) + .get("/all", async (c) => { + const res = await auth.api.listDeviceSessions({ + headers: c.req.raw.headers, + }); + return c.json(res); }); -}) -.get("/all", async (c) => { - const res = await auth.api.listDeviceSessions({ - headers: c.req.raw.headers, - }); - return c.json(res); -}); export default app; diff --git a/apps/api/app/api/[[...route]]/status.ts b/apps/api/app/api/[[...route]]/status.ts index e6b88ee..639dd8f 100644 --- a/apps/api/app/api/[[...route]]/status.ts +++ b/apps/api/app/api/[[...route]]/status.ts @@ -2,25 +2,25 @@ import { Hono } from "hono"; import { cache } from "@repo/cache"; const app = new Hono() -.get("/", async (c) => { - const dbStatus = await cache.lrange("db-latency:history", 0, -1); - const siteStatus = await cache.lrange("site-latency:history", 0, -1); - return c.json({ - dbStatus, - siteStatus, + .get("/", async (c) => { + const dbStatus = await cache.lrange("db-latency:history", 0, -1); + const siteStatus = await cache.lrange("site-latency:history", 0, -1); + return c.json({ + dbStatus, + siteStatus, + }); + }) + .get("/db", async (c) => { + const dbStatus = await cache.lrange("db-latency:history", 0, -1); + return c.json({ + dbStatus, + }); + }) + .get("/site", async (c) => { + const siteStatus = await cache.lrange("site-latency:history", 0, -1); + return c.json({ + siteStatus, + }); }); -}) -.get("/db", async (c) => { - const dbStatus = await cache.lrange("db-latency:history", 0, -1); - return c.json({ - dbStatus, - }); -}) -.get("/site", async (c) => { - const siteStatus = await cache.lrange("site-latency:history", 0, -1); - return c.json({ - siteStatus, - }); -}); export default app; diff --git a/apps/api/app/api/[[...route]]/test.ts b/apps/api/app/api/[[...route]]/test.ts index 047d723..ad9d985 100644 --- a/apps/api/app/api/[[...route]]/test.ts +++ b/apps/api/app/api/[[...route]]/test.ts @@ -1,8 +1,7 @@ import { Hono } from "hono"; import { prisma } from "@repo/db"; -const app = new Hono() -.get("/", async (c) => { +const app = new Hono().get("/", async (c) => { const user = await prisma.user.findMany(); return c.json({ user,