Skip to content

Commit

Permalink
Merge pull request #17 from Aditya-Jyoti/master
Browse files Browse the repository at this point in the history
fix: Change middleware hierarchy
  • Loading branch information
Aditya-Jyoti authored Dec 26, 2024
2 parents 5d2984e + 570698c commit 67b603d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ COPY init.sh .
RUN chmod +x init.sh

# Build the app (using TypeScript compiler)
RUN pnpm run build
RUN pnpm prisma generate

# Expose necessary ports
EXPOSE 3000
Expand Down
6 changes: 4 additions & 2 deletions init.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
pnpm prisma migrate deploy
pnpm run start
pnpm dlx prisma migrate deploy
pnpm dlx prisma generate
pnpm dlx build
pnpm dlx run start
21 changes: 11 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import { swaggerUI } from "@hono/swagger-ui";

import authRouter from "./routes/auth/index.js";
import userRouter from "./routes/user/index.js";
import { middleware } from "./lib/auth-provider.js";

const app = new OpenAPIHono();
app.openAPIRegistry.registerComponent("securitySchemes", "Bearer", {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
});

app.route("/auth", authRouter);
app.route("/user", userRouter);

app.get("/", (c) => {
return c.text("Server is alive!");
});

const port = 3000;
console.log(`Server is running on http://localhost:${port}`);

app.doc("/openapi", {
openapi: "3.0.0",
info: {
Expand All @@ -25,14 +27,13 @@ app.doc("/openapi", {
},
});

app.openAPIRegistry.registerComponent("securitySchemes", "Bearer", {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
});

app.get("/docs", swaggerUI({ url: "/openapi" }));

app.use(middleware);
app.route("/user", userRouter);

const port = 3000;
console.log(`Server is running on http://localhost:${port}`);
serve({
fetch: app.fetch,
port,
Expand Down
7 changes: 1 addition & 6 deletions src/routes/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import prisma from "./../../lib/prisma-client.js";
import { getUser, getUserById } from "./routes.js";

import { Role } from "@prisma/client";
import {
middleware,
checkRole,
getCurrentUser,
} from "../../lib/auth-provider.js";
import { checkRole, getCurrentUser } from "../../lib/auth-provider.js";

const userRouter = new OpenAPIHono();
userRouter.use("/*", middleware);

userRouter.openapi(getUser, async (ctx) => {
const user = getCurrentUser(ctx);
Expand Down

0 comments on commit 67b603d

Please sign in to comment.