mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-02 22:15:23 -04:00
Migrate apex redirect logic from next.config.ts to middleware for improved flexibility and maintainability
This commit is contained in:
26
web/middleware.ts
Normal file
26
web/middleware.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type {NextRequest} from 'next/server'
|
||||
import {NextResponse} from 'next/server'
|
||||
|
||||
const DOMAIN = 'compassmeet.com'
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
const host = request.headers.get('host') || ''
|
||||
const url = request.nextUrl.clone()
|
||||
|
||||
// Never redirect well-known files (Android + iOS app verification)
|
||||
if (url.pathname.startsWith('/.well-known/')) {
|
||||
return NextResponse.next()
|
||||
}
|
||||
|
||||
// apex → www
|
||||
if (host === DOMAIN) {
|
||||
url.hostname = 'www.compassmeet.com'
|
||||
return NextResponse.redirect(url, 308)
|
||||
}
|
||||
|
||||
return NextResponse.next()
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
||||
}
|
||||
@@ -112,12 +112,6 @@ const nextConfig: NextConfig = {
|
||||
},
|
||||
async redirects() {
|
||||
return [
|
||||
{
|
||||
source: '/((?!\\.well-known/assetlinks\\.json).*)',
|
||||
has: [{type: 'host', value: 'compassmeet.com'}],
|
||||
destination: 'https://www.compassmeet.com/:path*',
|
||||
permanent: true,
|
||||
},
|
||||
{source: '/discord', destination: 'https://discord.gg/8Vd7jzqjun', permanent: false},
|
||||
{source: '/patreon', destination: 'https://patreon.com/CompassMeet', permanent: false},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user