update apix.ts and siteurl.ts
This commit is contained in:
parent
3c8c450dc2
commit
100b44f024
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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}`;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue