Skip to content

Commit

Permalink
fix(Middleware): added middleware file back
Browse files Browse the repository at this point in the history
  • Loading branch information
andy1uu committed May 6, 2024
1 parent 88fc51a commit 0ab45f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/app/api/education/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ import type { NextRequest } from "next/server";

export const GET = async (request: NextRequest, response: NextResponse) => {
try {
const apiKey = request.headers.get("API_KEY");

if (apiKey !== process.env.REACT_APP_API_KEY) {
return new NextResponse(null, {
status: 401,
statusText: "Invalid API Key",
headers: { "Content-Type": "application/json" },
});
}

const client = await clientPromise;
const database = client.db(process.env.DATABASE_NAME);
const education = await database
Expand Down
18 changes: 18 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export const middleware = (request: NextRequest) => {
const apiKey = request.headers.get("API_KEY");

if (apiKey !== process.env.REACT_APP_API_KEY) {
return new NextResponse(null, {
status: 401,
statusText: "Invalid API Key",
headers: { "Content-Type": "application/json" },
});
}

return NextResponse.next();
};

export const config = { matcher: "/api/:path*" };

1 comment on commit 0ab45f3

@vercel
Copy link

@vercel vercel bot commented on 0ab45f3 May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.