-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmiddleware.ts
36 lines (28 loc) · 1.04 KB
/
middleware.ts
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
26
27
28
29
30
31
32
33
34
35
36
// import "server-only";
import createMiddleware from "next-intl/middleware";
import { AllLocales, LocaleConfig } from "./config/locale";
import { logger } from "./lib/logger";
import { updateSession } from "./lib/supabase/middleware";
import { NextRequest } from "next/server";
const intl = createMiddleware({
locales: AllLocales,
defaultLocale: LocaleConfig.defaultLocale,
localePrefix: "as-needed",
});
// export default withLogging(intl);
export async function middleware(request: NextRequest) {
// log request
const forwarded = request.headers.get("x-forwarded-for");
const ip = forwarded ? forwarded.split(/, /)[0] : "";
logger.info(`[${request.method}] [${ip}] ${request.url}`);
// intl request
const response = await intl(request);
// auth request
const rsp = updateSession(request, response);
return rsp;
}
export const config = {
// Match only internationalized pathnames
// matcher: "/((?!api|static|.*\\..*|_next).*)",
matcher: "/((?!api|static|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
};