Files
ai-directory-platform/packages/core/src/proxy.ts
T
AI Directory Platform 55f7ea5a04 feat: /en/* 改为直接 404(URL 即语言,无默认语言别名)
- 设计契约变更:/ 与 /* 英文站、/zh 与 /zh/* 中文站、/en 与 /en/* 非法路径
  直接 404(品牌 404 页),不再 307 规范化到无前缀形式
- proxy rewrite 到内部不存在路径渲染 not-found(404),URL 保持原样
- LanguageSwitcher 同步修复:切英文生成无前缀路径(此前产生 /en/ 会撞 404)
- 回归:/en/* 全部 404;/、/login、/zh/* 全部 200;语言切换双向闭环正常;
  mock 登录正常
2026-09-10 07:39:16 +00:00

34 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import createIntlMiddleware from 'next-intl/middleware';
import { routing } from './i18n/routing';
import { NextRequest, NextResponse } from 'next/server';
const intlMiddleware = createIntlMiddleware(routing);
/**
* # proxy
* 说明:站点入口中间件。URL 即语言(设计契约):
* - / 与 /* …… 英文站(默认语言,无前缀)
* - /zh 与 /zh/* …… 中文站
* - /en 与 /en/* …… 非法路径,直接 404(品牌 404 页)。
* 默认语言不提供带前缀的别名,避免 /en/* 与 /* 产生重复内容与重定向链。
*/
export function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;
if (pathname === '/en' || pathname.startsWith('/en/')) {
// rewrite 到不存在的内部路径 → Next 渲染 not-found(404),URL 保持原样
const url = request.nextUrl.clone();
url.pathname = '/__en_not_available__';
return NextResponse.rewrite(url, { status: 404 });
}
return intlMiddleware(request);
}
export const config = {
matcher: [
'/',
'/((?!api|_next|_vercel|.*\\..*).*)'
]
};