From aa99536a32ada1cee8a4b7e8ef67099a9d0c1531 Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan <43689091+ichsankurnia@users.noreply.github.com> Date: Tue, 10 Nov 2026 17:23:53 +0700 Subject: [PATCH] Route server requests through local API Use BASE_URL_API_LOCAL_SERVER for server-side data requests and load the layout session through the cached helper. Update production URLs to HTTPS and use 127.0.0.1 for local API endpoints. --- .env.production | 6 +++--- .env.staging | 2 +- app/layout.tsx | 5 ++--- lib/fetchData.ts | 8 ++++---- lib/get-access-data.tsx | 3 ++- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.env.production b/.env.production index acd396b..4da76aa 100644 --- a/.env.production +++ b/.env.production @@ -1,11 +1,11 @@ BASE_PATH = "" -NEXT_PUBLIC_APP_URL="http://hats.hisnutech.my.id" +NEXT_PUBLIC_APP_URL="https://hats.hisnutech.my.id" -BASE_URL_API_LOCAL_SERVER = http://localhost:7003/api/v1 +BASE_URL_API_LOCAL_SERVER = http://127.0.0.1:7003/api/v1 BASE_URL_API = https://api-hats.hisnutech.my.id/api/v1 BASE_URL_IMG = https://api-hats.hisnutech.my.id/ -NEXTAUTH_URL = http://hats.hisnutech.my.id +NEXTAUTH_URL = https://hats.hisnutech.my.id NEXTAUTH_URL_INTERNAL = http://36.66.3.44:7002 NEXTAUTH_SECRET = 4339d50684523526005c1fcb34be0bb1 diff --git a/.env.staging b/.env.staging index 355c06c..2b45afd 100644 --- a/.env.staging +++ b/.env.staging @@ -1,7 +1,7 @@ BASE_PATH = "" NEXT_PUBLIC_APP_URL="https://dev-hats.hisnutech.my.id" -BASE_URL_API_LOCAL_SERVER = http://localhost:7004/api/v1 +BASE_URL_API_LOCAL_SERVER = http://127.0.0.1:7004/api/v1 BASE_URL_API = https://api-hats-dev.hisnutech.my.id/api/v1 BASE_URL_IMG = https://api-hats.hisnutech.my.id/ diff --git a/app/layout.tsx b/app/layout.tsx index 445c1b4..b0e50f2 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -4,7 +4,7 @@ import 'react-lazy-load-image-component/src/effects/blur.css'; import type { Metadata, Viewport } from 'next' import { Plus_Jakarta_Sans } from 'next/font/google' -import { getServerSession } from 'next-auth' +import { getCacheServerSession } from '@/lib/get-access-data' import { ThemeProvider } from '@/providers/ThemeProvider' import SessionProvider from '@/providers/SessionProvider' @@ -13,7 +13,6 @@ import AntdConfigProvider from '@/providers/AntdConfigProvider'; import ProgressBarProviders from '@/providers/ProgressBarProvider'; import { TooltipProvider } from '@/components/ui/tooltip'; import ServiceWorkerRegister from '@/components/pwa/ServiceWorkerRegister'; -import { authOptions } from '@/lib/auth'; const jakarta = Plus_Jakarta_Sans({ subsets: ['latin'] }) @@ -99,7 +98,7 @@ export default async function RootLayout({ // FOR INSECURE SSL (ex: Self Signed Certificates) // process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' - const session = await getServerSession(authOptions) + const session = await getCacheServerSession() return ( diff --git a/lib/fetchData.ts b/lib/fetchData.ts index db905c1..924908e 100644 --- a/lib/fetchData.ts +++ b/lib/fetchData.ts @@ -4,10 +4,10 @@ import { logger } from "./logger" import { getCacheServerSession } from "./get-access-data" export default async function fetchData(url: string = '/', cache: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" = 'default', next?: NextFetchRequestConfig) { - const { BASE_URL_API } = process.env + const baseUrl = process.env.BASE_URL_API_LOCAL_SERVER const session = await getCacheServerSession() - const res = await fetch(BASE_URL_API + url, { + const res = await fetch(baseUrl + url, { headers: { "Content-Type": "application/json", Authorization: `Bearer ${session?.user.access_token}`, @@ -32,10 +32,10 @@ export default async function fetchData(url: string = '/', cache: "default" | "f } export async function fetchDataWithPost(url: string = '/', payload: any = {}, cache: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" = 'default', next?: NextFetchRequestConfig) { - const { BASE_URL_API } = process.env + const baseUrl = process.env.BASE_URL_API_LOCAL_SERVER const session = await getCacheServerSession() - const res = await fetch(BASE_URL_API + url, { + const res = await fetch(baseUrl + url, { headers: { "Content-Type": "application/json", Authorization: `Bearer ${session?.user.access_token}`, diff --git a/lib/get-access-data.tsx b/lib/get-access-data.tsx index d99cf47..9cbcfc9 100644 --- a/lib/get-access-data.tsx +++ b/lib/get-access-data.tsx @@ -22,7 +22,8 @@ export const getAccessData = cache(async () => { redirect("/auth?error=Session%20error%20or%20has%20expired"); } - const res = await fetch(`${process.env.BASE_URL_API}/role/${session?.user.detail.role.id}`, + const baseUrl = process.env.BASE_URL_API_LOCAL_SERVER + const res = await fetch(`${baseUrl}/role/${session?.user.detail.role.id}`, { headers: { "Content-Type": "application/json",