SPB Git

Repository Public

proxy.ts 3.3 KB 76 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : ORIX App Universe8 * File             : src/proxy.ts9 * Module           : src10 * Repository       : https://git.spboucher.ai/orix-spboucher-ai11 * Project Website  : https://www.orixlab.dev12 * Created          : 2026-11-2113 * Last Modified    : 2026-11-2114 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { NextResponse, type NextRequest } from "next/server";4445/**46 * Locale routing: English is served at the root (/apps/scan), French-Canadian under /fr.47 * Internally every public page lives under /[locale]; un-prefixed paths are rewritten to /en.48 * No automatic language redirect: the address a visitor (or a crawler) asks for is the one they get.49 */50const ADMIN = (() => { try { return new URL(process.env.APP_URL ?? ""); } catch { return null; } })();5152export function proxy(req: NextRequest) {53  const { pathname } = req.nextUrl;54  if (pathname === "/admin" || pathname.startsWith("/admin/")) {55    // The site answers on more than one host; the administration (and its passkeys) lives on exactly one.56    const host = (req.headers.get("x-forwarded-host") ?? req.headers.get("host") ?? "").toLowerCase();57    if (ADMIN && host && host !== ADMIN.host) return NextResponse.redirect(new URL(pathname + req.nextUrl.search, ADMIN.origin), 307);58    return NextResponse.next();59  }60  if (pathname === "/en" || pathname.startsWith("/en/")) {61    const url = req.nextUrl.clone();62    url.pathname = pathname.slice(3) || "/";63    return NextResponse.redirect(url, 308);64  }65  const headers = new Headers(req.headers);66  headers.set("x-orix-path", pathname);67  if (pathname === "/fr" || pathname.startsWith("/fr/")) return NextResponse.next({ request: { headers } });68  const url = req.nextUrl.clone();69  url.pathname = `/en${pathname === "/" ? "" : pathname}`;70  return NextResponse.rewrite(url, { request: { headers } });71}7273export const config = {74  matcher: ["/admin/:path*", "/((?!api/|admin|download/|media/|_next/|apps/[^/]+/[^/]+\\.|brand/|og/|.*\\.[a-z0-9]+$).*)"],75};76
Files main
Menu

Theme