fix: usage of internal api

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-10-08 21:40:37 +02:00 committed by Philip Molares
parent 3076bb4cc3
commit a2b291294e
4 changed files with 37 additions and 41 deletions

View file

@ -39,7 +39,20 @@ export abstract class ApiRequestBuilder<ResponseType> {
* @return the base url
*/
private determineBaseUrl(baseUrl?: string) {
return typeof window !== 'undefined' ? baseUrl ?? '/' : baseUrlFromEnvExtractor.extractBaseUrls().internalApiUrl
if (this.isSSR()) {
const internalApiUrl = baseUrlFromEnvExtractor.extractBaseUrls().internalApiUrl
const actualBaseUrl = internalApiUrl ?? baseUrl
if (actualBaseUrl === undefined) {
throw new Error("Can't make request without forced base url and without internal api url")
}
return actualBaseUrl
} else {
return baseUrl ?? '/'
}
}
private isSSR() {
return typeof window === 'undefined'
}
protected async sendRequestAndVerifyResponse(httpMethod: RequestInit['method']): Promise<ApiResponse<ResponseType>> {