Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import { NextRequest, NextResponse } from "next/server"
import createMiddleware from "next-intl/middleware"

import { routing } from "./src/i18n/routing"
import { DEFAULT_LOCALE } from "./src/lib/constants"

export default createMiddleware(routing)
const handleI18nRouting = createMiddleware(routing)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

// Example middleware for logging requests
function requestLogger(req, res, next) {
console.log(${req.method} ${req.url});
next(); // Call the next middleware
}


export default function middleware(request: NextRequest) {
const response = handleI18nRouting(request)

// Upgrade default-locale strip redirects from 307 to 301 for SEO
if (response.status === 307) {
const pathname = request.nextUrl.pathname
const defaultPrefix = `/${DEFAULT_LOCALE}`
if (
pathname === defaultPrefix ||
pathname.startsWith(`${defaultPrefix}/`)
) {
return new NextResponse(null, { status: 301, headers: response.headers })
}
}

return response
}

// Simplified matcher pattern
export const config = {
Expand Down