| import { | |
| LayoutService, | |
| RestLayoutService, | |
| GraphQLLayoutService, | |
| constants, | |
| } from "@sitecore-jss/sitecore-jss-nextjs"; | |
| import config from "temp/config"; | |
| /** | |
| * Factory responsible for creating a LayoutService instance | |
| */ | |
| export class LayoutServiceFactory { | |
| /** | |
| * @param {string} siteName site name | |
| * @returns {LayoutService} service instance | |
| */ | |
| create(siteName: string): LayoutService { | |
| return process.env.FETCH_WITH === constants.FETCH_WITH.GRAPHQL | |
| ? new GraphQLLayoutService({ | |
| endpoint: config.graphQLEndpoint, | |
| apiKey: config.sitecoreApiKey, | |
| siteName, | |
| }) | |
| : new RestLayoutService({ | |
| apiHost: config.sitecoreApiHost, | |
| apiKey: config.sitecoreApiKey, | |
| siteName, | |
| configurationName: "default", | |
| }); | |
| } | |
| } | |
| /** LayoutServiceFactory singleton */ | |
| export const layoutServiceFactory = new LayoutServiceFactory(); | |