Skip to content

crelte / / Crelte

Type Alias: Crelte ​

ts
type Crelte = object;

This is Crelte a container of useful features and functions.

In svelte contexts for each of these functions and classes there should be a getter function like getCrelte() or getRouter().

Note ​

Plugins and other instances could modify this type, so when extending cloning or similar use the spread operator instead of naming all "properties".

Properties ​

bodyClass ​

ts
bodyClass: BodyClass;

Get the BodyClass instance


config ​

ts
config: Required<Config>;

Config


cookies ​

ts
cookies: Cookies;

Get the Cookies instance


events ​

ts
events: Events;

Get the Events instance


globals ​

ts
globals: Globals;

Get the Globals instance


plugins ​

ts
plugins: Plugins;

Get the Plugins instance


queries ​

ts
queries: Queries;

Get the Queries instance


router ​

ts
router: Router;

Get the Router instance


ssrCache ​

ts
ssrCache: SsrCache;

Get the SSR cache

Methods ​

backendUrl() ​

ts
backendUrl(path?): URL;

returns the backend url with an optional path

Note ​

For the origin the ENDPOINT_URL env variable is used

Parameters ​

path? ​

string

Returns ​

URL


frontendUrl() ​

ts
frontendUrl(path?): URL;

returns the frontend url with an optional path

Note ​

On the client this will always be the current origin and on the server it will be the from the env FRONTEND_URL env variable

Parameters ​

path? ​

string

Returns ​

URL


getEnv() ​

Call Signature ​

ts
getEnv(name): string;

returns an env variable from the craft/.env file. All env variables need to start with VITE_ except ENDPOINT_URL, CRAFT_BASE_CP_URL and FRONTEND_URL

Parameters ​
name ​

"ENDPOINT_URL"

Returns ​

string

Call Signature ​

ts
getEnv(name): string;
Parameters ​
name ​

"CRAFT_BASE_CP_URL"

Returns ​

string

Call Signature ​

ts
getEnv(name): string;
Parameters ​
name ​

"FRONTEND_URL"

Returns ​

string

Call Signature ​

ts
getEnv(name): string | null;
Parameters ​
name ​

string

Returns ​

string | null


getGlobalStore() ​

ts
getGlobalStore<T>(name): Readable<T> | null;

returns a store which contains a globalSet

Note ​

This only works in loadData, in loadGlobalData this will always return null. In that context you should use CrelteRequest.getGlobalAsync

Type Parameters ​

T ​

T = any

Parameters ​

name ​

string

Returns ​

Readable<T> | null


getPlugin() ​

ts
getPlugin(name): Plugin | null;

Get a Plugin by name

Parameters ​

name ​

string

Returns ​

Plugin | null


query() ​

ts
query(
   query, 
   variables?, 
opts?): Promise<unknown>;

Run a GraphQl Query

Parameters ​

query ​

Query

the default export from a graphql file or the gqlquery {} function

variables? ​

Record<string, unknown>

variables that should be passed to the graphql query

opts? ​

QueryOptions

Returns ​

Promise<unknown>


toRequest() ​

ts
toRequest(req?): CrelteRequest;

returns a new CrelteRequest instance either with the current route or a provided one

Note ​

This is useful if you want to create a stateful crelte to use in loadData context

Parameters ​

req? ​

| Route | Request

Returns ​

CrelteRequest