Compare commits

...
1 Commits
Author SHA1 Message Date
3970260761 2c8a68b064 feat: middleware 首访未选线路时跳转 /ipv6 选择页 (v-fixed98)
Docker Build & Test / build (push) Canceled after 0s
Docker Build & Test / test (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/amd64) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm/v7) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm64) (push) Canceled after 0s
Build & Push Docker image / merge-images (push) Canceled after 0s
Release / release (push) Canceled after 0s
Release / docker (push) Canceled after 0s
2026-11-09 18:06:17 +08:00
4 changed files with 19 additions and 2 deletions

No files matched your search

+2 -2
View File
@@ -33,7 +33,7 @@ COPY . .
RUN find ./src -type f -name "route.ts" -print0 \
| xargs -0 sed -i "s/export const runtime = 'edge';/export const runtime = 'nodejs';/g"
ENV DOCKER_ENV=true
ENV NEXT_PUBLIC_SITE_VERSION=fixed97
ENV NEXT_PUBLIC_SITE_VERSION=fixed98
# For Docker builds, force dynamic rendering to read runtime environment variables.
RUN sed -i "/const inter = Inter({ subsets: \['latin'] });/a export const dynamic = 'force-dynamic';" src/app/layout.tsx
@@ -52,7 +52,7 @@ ENV NODE_ENV=production
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
ENV DOCKER_ENV=true
ENV NEXT_PUBLIC_SITE_VERSION=fixed97
ENV NEXT_PUBLIC_SITE_VERSION=fixed98
# 从构建器中复制 standalone 输出
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
+2
View File
@@ -91,6 +91,7 @@ export default function IPv6Page() {
try { localStorage.setItem('__v6dest', which); } catch (e) { // ignore
// ignore
}
document.cookie = `__v6dest=${which}; path=/; max-age=31536000; samesite=lax`;
// 去掉 search 里的 back 参数,避免透传到目标地址
const qs = new URLSearchParams(window.location.search);
qs.delete('back');
@@ -125,6 +126,7 @@ export default function IPv6Page() {
try { localStorage.setItem('__v6dest', 'v6'); } catch (e) { // ignore
// ignore
}
document.cookie = '__v6dest=v6; path=/; max-age=31536000; samesite=lax';
let targetBack = back;
try {
const s = sessionStorage.getItem('__v6back');
+2
View File
@@ -8,6 +8,8 @@ export default function Ipv6FirstVisitGate() {
try {
if (location.hostname !== 'tv.88531.cn') return; // 仅公网 IPv4 入口;LAN/IPv6 线路不跳转(避免循环)
if (location.pathname === '/ipv6') return;
// middleware 已记住线路(cookie)即视为已选择,不再重复弹
if (/(^|;\s*)__v6dest=/.test(document.cookie)) return;
if (localStorage.getItem('__v6dest')) return; // 已记住线路,不打扰
sessionStorage.setItem('__v6back', location.pathname + location.search + location.hash);
location.replace('/ipv6');
+13
View File
@@ -49,6 +49,19 @@ export async function middleware(request: NextRequest) {
return NextResponse.next();
}
// 首访线路选择(源码化,替代旧 patches/patch_license.js 的 V6-PROBE):
// 公网 IPv4 入口且未记住线路(cookie __v6dest 缺失)时,先跳 /ipv6 选择页再回来
const hostName = (request.headers.get('host') || request.nextUrl.hostname || '').split(':')[0];
if (
hostName === 'tv.88531.cn' &&
pathname !== '/warning' &&
!request.cookies.get('__v6dest')
) {
const u = new URL('/ipv6', request.url);
u.searchParams.set('back', pathname + request.nextUrl.search);
return NextResponse.redirect(u);
}
const storageType = process.env.NEXT_PUBLIC_STORAGE_TYPE || 'localstorage';
if (!process.env.AUTH_PASSWORD) {