From da77dc168dc7f3f0c8146077ff6f17bbef2594c2 Mon Sep 17 00:00:00 2001 From: ghorbani Date: Thu, 30 Jul 2026 15:01:30 +0330 Subject: [PATCH] feat: implement API proxy, add TokenSwitcher component for testing, and configure request caching headers --- next.config.ts | 21 +++- src/app/api/proxy/route.ts | 12 +- src/app/layout.tsx | 24 ++-- src/app/request-accepted/page.tsx | 27 ++--- src/components/ui/token-switcher.tsx | 174 +++++++++++++++++++++++++++ src/lib/http.ts | 14 +++ 6 files changed, 242 insertions(+), 30 deletions(-) create mode 100644 src/components/ui/token-switcher.tsx diff --git a/next.config.ts b/next.config.ts index d679207..95db85b 100644 --- a/next.config.ts +++ b/next.config.ts @@ -40,7 +40,26 @@ const nextConfig: NextConfig = { async headers() { return [ { - source: "/:path*", + // Never cache API proxy responses – always fetch fresh from backend + source: "/api/:path*", + headers: [ + { + key: "Cache-Control", + value: "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0", + }, + { + key: "Pragma", + value: "no-cache", + }, + { + key: "Expires", + value: "0", + }, + ], + }, + { + // Static pages – moderate cache + source: "/:path((?!api/).*)", headers: [ { key: "Cache-Control", diff --git a/src/app/api/proxy/route.ts b/src/app/api/proxy/route.ts index 9bb7794..e7f4159 100644 --- a/src/app/api/proxy/route.ts +++ b/src/app/api/proxy/route.ts @@ -305,10 +305,20 @@ async function proxyRequest(request: NextRequest) { + const responseHeaders = getResponseHeaders(upstreamResponse.headers); + + // Force no caching on API proxy responses – always fetch fresh data + responseHeaders.set( + "Cache-Control", + "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0", + ); + responseHeaders.set("Pragma", "no-cache"); + responseHeaders.set("Expires", "0"); + return new Response(responseBody, { status: upstreamResponse.status, statusText: upstreamResponse.statusText, - headers: getResponseHeaders(upstreamResponse.headers), + headers: responseHeaders, }); } catch (error) { if (error instanceof ProxyError) { diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 73de8d5..32eac83 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,9 +1,11 @@ -import type { Metadata } from "next"; +import type { Metadata, Viewport } from "next"; import { Amiri } from "next/font/google"; import localFont from "next/font/local"; +import Script from "next/script"; import Providers from "./providers"; import "./globals.css"; import DevClickToComponent from "@/components/dev/dev-click-to-component"; +import TokenSwitcher from "@/components/ui/token-switcher"; const faminela = localFont({ src: "../../public/fonts/Faminela/Faminela.otf", @@ -25,11 +27,12 @@ const amiri = Amiri({ export const metadata: Metadata = { title: "Habib Marriage", description: "Islamic Marriage Platform", - viewport: { - width: "device-width", - initialScale: 1, - maximumScale: 1, - }, +}; + +export const viewport: Viewport = { + width: "device-width", + initialScale: 1, + maximumScale: 1, themeColor: "#ffffff", }; @@ -43,8 +46,9 @@ export default function RootLayout({ -