From 100b44f024f88456b259556faa0624a6e8e5b886 Mon Sep 17 00:00:00 2001 From: faisolavolut Date: Fri, 7 Feb 2025 11:08:25 +0700 Subject: [PATCH] update apix.ts and siteurl.ts --- utils/apix.ts | 8 +++++++- utils/siteurl.ts | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/utils/apix.ts b/utils/apix.ts index c0828d1..916843b 100644 --- a/utils/apix.ts +++ b/utils/apix.ts @@ -14,6 +14,7 @@ type apixType = { label: string | ((item: any) => string); }; header?: "normal" | "form"; + options?: any; }; export const apix = async ({ @@ -26,6 +27,7 @@ export const apix = async ({ type = "usual", header = "normal", keys, + options, }: apixType) => { const root_url = `${ port === "portal" @@ -56,13 +58,16 @@ export const apix = async ({ try { switch (method) { case "get": - result = await api.get(root_url); + result = await api.get(root_url, { + ...options, + }); break; case "post": result = await api.post(root_url, requestData, { headers: type === "form" ? { "Content-Type": "multipart/form-data" } : {}, + ...options, }); break; @@ -70,6 +75,7 @@ export const apix = async ({ result = await api.put(root_url, requestData, { headers: type === "form" ? { "Content-Type": "multipart/form-data" } : {}, + ...options, }); break; diff --git a/utils/siteurl.ts b/utils/siteurl.ts index 1a7d4a0..c3c456e 100644 --- a/utils/siteurl.ts +++ b/utils/siteurl.ts @@ -1,6 +1,18 @@ import dotenv from "dotenv"; dotenv.config(); -export const siteurl = (param: string) => { +export const siteurl = ( + param: string, + port?: "portal" | "recruitment" | "mpp" +) => { if (param && param.startsWith("http")) return param; - return `${process.env.NEXT_PUBLIC_BASE_URL + param}`; + const root_url = `${ + port === "portal" + ? process.env.NEXT_PUBLIC_API_PORTAL + : port === "recruitment" + ? process.env.NEXT_PUBLIC_API_RECRUITMENT + : port === "mpp" + ? process.env.NEXT_PUBLIC_API_MPP + : process.env.NEXT_PUBLIC_BASE_URL + }${param}`; + return `${root_url}`; };