forked from ellertsmari/io.vefskoliv2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
25 lines (19 loc) · 852 Bytes
/
middleware.ts
File metadata and controls
25 lines (19 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import NextAuth from "next-auth";
import { authConfig } from "./auth.config";
export default NextAuth(authConfig).auth;
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
const url = request.nextUrl.clone();
// Check if the path starts with `/` and rewrite to act as if it’s under `/pages`
// For example, `/guides` would be rewritten to `/pages/guides/page.tsx`
if (url.pathname.startsWith("/")) {
url.pathname = `/pages${url.pathname}/`; // Adjust this based on your directory structure
return NextResponse.rewrite(url);
}
return NextResponse.next();
}
export const config = {
// https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
matcher: ["/((?!api|_next/static|_next/image|.*\\.png$).*)"],
};