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.
This commit is contained in:
Ichsan Kurniawan
2026-11-10 17:23:53 +07:00
parent b329a89f2d
commit aa99536a32
5 changed files with 12 additions and 12 deletions
+3 -3
View File
@@ -1,11 +1,11 @@
BASE_PATH = "" 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_API = https://api-hats.hisnutech.my.id/api/v1
BASE_URL_IMG = https://api-hats.hisnutech.my.id/ 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_URL_INTERNAL = http://36.66.3.44:7002
NEXTAUTH_SECRET = 4339d50684523526005c1fcb34be0bb1 NEXTAUTH_SECRET = 4339d50684523526005c1fcb34be0bb1
+1 -1
View File
@@ -1,7 +1,7 @@
BASE_PATH = "" BASE_PATH = ""
NEXT_PUBLIC_APP_URL="https://dev-hats.hisnutech.my.id" 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_API = https://api-hats-dev.hisnutech.my.id/api/v1
BASE_URL_IMG = https://api-hats.hisnutech.my.id/ BASE_URL_IMG = https://api-hats.hisnutech.my.id/
+2 -3
View File
@@ -4,7 +4,7 @@ import 'react-lazy-load-image-component/src/effects/blur.css';
import type { Metadata, Viewport } from 'next' import type { Metadata, Viewport } from 'next'
import { Plus_Jakarta_Sans } from 'next/font/google' 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 { ThemeProvider } from '@/providers/ThemeProvider'
import SessionProvider from '@/providers/SessionProvider' import SessionProvider from '@/providers/SessionProvider'
@@ -13,7 +13,6 @@ import AntdConfigProvider from '@/providers/AntdConfigProvider';
import ProgressBarProviders from '@/providers/ProgressBarProvider'; import ProgressBarProviders from '@/providers/ProgressBarProvider';
import { TooltipProvider } from '@/components/ui/tooltip'; import { TooltipProvider } from '@/components/ui/tooltip';
import ServiceWorkerRegister from '@/components/pwa/ServiceWorkerRegister'; import ServiceWorkerRegister from '@/components/pwa/ServiceWorkerRegister';
import { authOptions } from '@/lib/auth';
const jakarta = Plus_Jakarta_Sans({ subsets: ['latin'] }) const jakarta = Plus_Jakarta_Sans({ subsets: ['latin'] })
@@ -99,7 +98,7 @@ export default async function RootLayout({
// FOR INSECURE SSL (ex: Self Signed Certificates) // FOR INSECURE SSL (ex: Self Signed Certificates)
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' // process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
const session = await getServerSession(authOptions) const session = await getCacheServerSession()
return ( return (
<html lang="en" suppressHydrationWarning> <html lang="en" suppressHydrationWarning>
+4 -4
View File
@@ -4,10 +4,10 @@ import { logger } from "./logger"
import { getCacheServerSession } from "./get-access-data" 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) { 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 session = await getCacheServerSession()
const res = await fetch(BASE_URL_API + url, { const res = await fetch(baseUrl + url, {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${session?.user.access_token}`, 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) { 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 session = await getCacheServerSession()
const res = await fetch(BASE_URL_API + url, { const res = await fetch(baseUrl + url, {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${session?.user.access_token}`, Authorization: `Bearer ${session?.user.access_token}`,
+2 -1
View File
@@ -22,7 +22,8 @@ export const getAccessData = cache(async () => {
redirect("/auth?error=Session%20error%20or%20has%20expired"); 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: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",