@progress/sitefinity-nextjs-sdk
Version:
Provides OOB widgets developed using the Next.js framework, which includes an abstraction layer for Sitefinity communication. Additionally, it offers an expanded API, typings, and tools for further development and integration.
44 lines (43 loc) • 1.65 kB
JavaScript
export class RootUrlService {
static getClientCmsUrl() {
let publicUrl = `${process.env['NEXT_PUBLIC_SF_CMS_URL'] || ''}`;
if (publicUrl.endsWith('/')) {
publicUrl = publicUrl.substring(0, publicUrl.length - 1);
}
return publicUrl;
}
static getClientServiceUrl() {
return `${RootUrlService.getClientCmsUrl()}/${RootUrlService.getWebServicePath()}`;
}
static getServerCmsUrl() {
let rootUrl = process.env['SF_CMS_URL'];
if (rootUrl && rootUrl.endsWith('/')) {
rootUrl = rootUrl.substring(0, rootUrl.length - 1);
}
return rootUrl;
}
static getServerCmsServiceUrl() {
return `${RootUrlService.getServerCmsUrl() || ''}/${RootUrlService.getWebServicePath()}`;
}
static getWebServicePath() {
let webServicePath = process?.env?.SF_WEBSERVICE_PATH;
if (!webServicePath) {
webServicePath = 'api/default';
}
else {
// removes any leading and trailing slashes from the end of the string.
webServicePath = webServicePath.replace(/^\/+|\/+$/g, '');
}
return webServicePath;
}
static getSearchWebServicePath() {
let searchWebServicePath = process.env.NEXT_PUBLIC_SF_SEARCH_WEBSERVICE_PATH;
if (searchWebServicePath) {
searchWebServicePath = searchWebServicePath.trim();
// removes any trailing slashes from the end of the string.
const trimmed = searchWebServicePath.replace(/\/+$/, '');
return trimmed;
}
return this.getWebServicePath();
}
}