-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
30 lines (26 loc) · 838 Bytes
/
proxy.ts
File metadata and controls
30 lines (26 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { updateSession } from "@/lib/supabase/middleware";
/**
* Proxy rules for SMSHub
* - Redirect www.smshub.dev → smshub.dev
* - Auth session management (Supabase)
*/
export async function proxy(request: NextRequest) {
const hostname = request.headers.get("host") || "";
// Redirect www to non-www
if (hostname.startsWith("www.")) {
const url = request.nextUrl.clone();
const nonWww = hostname.replace(/^www\./, "");
url.host = nonWww;
url.protocol = "https";
return NextResponse.redirect(url, 301);
}
// Auth session handling
return await updateSession(request);
}
export const config = {
matcher: [
"/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
],
};