Shared:Utils:NextSSRHelper: remove flag for disable internal requests

This commit is contained in:
Timofey Boyko 2024-06-19 14:35:11 +03:00
parent 60aa632984
commit f8b86220bc

View File

@ -24,7 +24,7 @@
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
import { headers } from "next/headers";
import { headers, cookies } from "next/headers";
const API_PREFIX = "api/2.0";
@ -39,12 +39,8 @@ export const getBaseUrl = () => {
return baseURL;
};
export const getAPIUrl = (internalRequest: boolean) => {
const baseUrl = internalRequest
? process.env.API_HOST?.trim() ?? getBaseUrl()
: getBaseUrl();
// const baseUrl = getBaseUrl();
export const getAPIUrl = () => {
const baseUrl = process.env.API_HOST?.trim() ?? getBaseUrl();
const baseAPIUrl = `${baseUrl}/${API_PREFIX}`;
@ -56,11 +52,11 @@ export const createRequest = (
newHeaders: [string, string][],
method: string,
body?: string,
internalRequest: boolean = true,
) => {
const hdrs = new Headers(headers());
const cookieStore = cookies();
const apiURL = getAPIUrl(internalRequest);
const apiURL = getAPIUrl();
newHeaders.forEach((hdr) => {
if (hdr[0]) hdrs.set(hdr[0], hdr[1]);
@ -70,6 +66,10 @@ export const createRequest = (
if (baseURL && process.env.API_HOST?.trim()) hdrs.set("origin", baseURL);
const authToken = cookieStore.get("asc_auth_key")?.value;
if (authToken) hdrs.set("Authorization", authToken);
const urls = paths.map((path) => `${apiURL}${path}`);
const requests = urls.map(