Skip to content

Commit

Permalink
fix(web): clean up api
Browse files Browse the repository at this point in the history
  • Loading branch information
cstrnt committed Sep 4, 2024
1 parent 53e816e commit 6a5eac6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.
23 changes: 3 additions & 20 deletions apps/web/src/api/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
import { env } from "env/server.mjs";
import type { Context, MiddlewareHandler } from "hono";
import type { MiddlewareHandler } from "hono";
import { getCookie } from "hono/cookie";
import type { GetServerSidePropsContext } from "next";
import type { DefaultSession } from "next-auth";
import type { Session } from "next-auth";
import { decode } from "next-auth/jwt";
import { getServerAuthSession } from "server/common/get-server-auth-session";
import type { UserSession } from "types/next-auth";

export async function getHonoSession(c: Context) {
return await getServerAuthSession({
req: {
...c.req.raw.clone(),
cookies: getCookie(c),
} as unknown as GetServerSidePropsContext["req"],
res: {
...c.res,
getHeader: (h: string) => c.req.header(h),
setHeader: (h: string, v: string) => c.header(h, v),
} as unknown as GetServerSidePropsContext["res"],
});
}

export const authMiddleware: MiddlewareHandler<{
Variables: {
user: UserSession & DefaultSession["user"];
user: NonNullable<Session["user"]>;
};
}> = async (c, next) => {
const tokenCookie = getCookie(
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { makeConfigRoute } from "api/routes/v1_config";
import { makeProjectDataRoute } from "api/routes/v1_project_data";
import { Hono } from "hono";
import { cors } from "hono/cors";
import { logger } from "hono/logger";
import { makeHealthRoute } from "./routes/health";
import { makeIntegrationsRoute } from "./routes/integrations";
import { makeLegacyProjectDataRoute } from "./routes/legacy_project_data";
Expand All @@ -11,7 +10,7 @@ import { makeEventRoute } from "./routes/v1_event";
export const app = new Hono()
.basePath("/api")
// base middleware
.use("*", logger())

.use("*", cors({ origin: "*", maxAge: 86400 }))
.route("/health", makeHealthRoute())
// legacy routes
Expand Down
4 changes: 0 additions & 4 deletions apps/web/src/api/routes/v1_project_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ export function makeProjectDataRoute() {
const app = new Hono()
.get(
"/:projectId",
cors({
origin: "*",
maxAge: 86400,
}),
zValidator(
"query",
z.object({
Expand Down

0 comments on commit 6a5eac6

Please sign in to comment.