Skip to content

Singleton

We can create a client instance in a host program, rather than in starsquid, so we can more flexibly manage the client. Initialize a Squidex client using SquidexClientFactory method from module "starsquid/api".

/src/scripts/client.ts
import { SquidexClientFactory } from "starsquid/api";
export const squidexClient = SquidexClientFactory(
import.meta.env.SQUIDEX_APP_NAME,
import.meta.env.SQUIDEX_CLIENT_ID,
import.meta.env.SQUIDEX_CLIENT_SECRET,
import.meta.env.SQUIDEX_URL
);

Then passing the squidexClient. It will use you already initialize client to fetch data from Squidex. That means it won’t create a new instance of SquidexClient, which implements the singletong feature, and you can also use this singleton to do more things, such as fetch data in real time.

src/content.config.ts
import { squidexCollections } from "starsquid/loaders";
import { squidexClient } from "./scripts/client";
export const collections = squidexCollections({
squidexUrl: import.meta.env.SQUIDEX_URL,
squidexAppName: import.meta.env.SQUIDEX_APP_NAME,
squidexClientId: import.meta.env.SQUIDEX_CLIENT_ID,
squidexClientSecret: import.meta.env.SQUIDEX_CLIENT_SECRET,
squidexClient: squidexClient,
});

the relationship between App, Collection and Squidex Client.

The relationship between App, Collection and Squidex Client.

Factory writing inspired by astro-ghostcms-loader.