nomadro/apps/nomadvip/middleware.ts
eric 56b29205e7 Integrate four verticals into nomadro portal with shared packages and API gateway.
Mount /vip with nomadvip+payjsapi, add @nomadro/pay|pb|sdk, apps/api, /admin shell, and backup/rollback scripts under git.nomadro.cn workflow.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 20:16:44 -05:00

33 lines
949 B
TypeScript

import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
/** 生产域名:微信内访问无协议或 http 时常异常,统一 308 到 HTTPS */
const FORCE_HTTPS_HOSTS = new Set(["vip.hackrobot.cn", "www.vip.hackrobot.cn"]);
export function middleware(request: NextRequest) {
const rawHost = request.headers.get("host");
const host = rawHost?.split(":")[0]?.toLowerCase() ?? "";
if (!host || !FORCE_HTTPS_HOSTS.has(host)) {
return NextResponse.next();
}
const forwarded = request.headers.get("x-forwarded-proto");
const proto = forwarded?.split(",")[0]?.trim().toLowerCase();
const url = request.nextUrl.clone();
const isHttp =
proto === "http" ||
(proto === undefined && url.protocol === "http:");
if (isHttp) {
url.protocol = "https:";
return NextResponse.redirect(url, 308);
}
return NextResponse.next();
}
export const config = {
matcher: ["/:path*"],
};