Files
klz-cables.com/middleware.ts
Marc Mintel c70288bba7
Some checks failed
Build & Deploy KLZ Cables / 🔍 Prepare Environment (push) Successful in 39s
Build & Deploy KLZ Cables / 🧪 Quality Assurance (push) Successful in 1m33s
Build & Deploy KLZ Cables / 🏗️ Build Gatekeeper (push) Successful in 22s
Build & Deploy KLZ Cables / 🏗️ Build App (push) Successful in 4m47s
Build & Deploy KLZ Cables / 🚀 Deploy (push) Successful in 48s
Build & Deploy KLZ Cables / ⚡ PageSpeed (push) Failing after 3m50s
Build & Deploy KLZ Cables / 🔔 Notifications (push) Successful in 2s
feat: Enhance Directus URL resolution for internal and proxy paths, and adjust Traefik host variable interpolation.
2026-02-06 11:29:10 +01:00

39 lines
1.2 KiB
TypeScript

import createMiddleware from 'next-intl/middleware';
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
// Create the internationalization middleware
const intlMiddleware = createMiddleware({
// A list of all locales that are supported
locales: ['en', 'de'],
// Used when no locale matches
defaultLocale: 'en',
});
// Main middleware that logs all requests
export default function middleware(request: NextRequest) {
const startTime = Date.now();
const { method, url, headers } = request;
const userAgent = headers.get('user-agent') || 'unknown';
const referer = headers.get('referer') || 'none';
const ip = headers.get('x-forwarded-for') || headers.get('x-real-ip') || 'unknown';
// Log incoming request
console.log(`Incoming request: method=${method} host=${headers.get('host')} url=${url}`);
try {
// Apply internationalization middleware
const response = intlMiddleware(request);
return response;
} catch (error) {
console.error(`Request failed: method=${method} url=${url}`, error);
throw error;
}
}
export const config = {
// Match only internationalized pathnames
matcher: ['/((?!api|_next|_vercel|health|.*\\..*).*)', '/', '/(de|en)/:path*'],
};