Type Alias: Crelte
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
config
config: Required<Config>;Config
cookies
cookies: Cookies;Get the Cookies instance
events
events: Events;Get the Events instance
globals
globals: Globals;Get the Globals instance
plugins
plugins: Plugins;Get the Plugins instance
queries
queries: Queries;Get the Queries instance
router
router: Router;Get the Router instance
ssrCache
ssrCache: SsrCache;Get the SSR cache
Methods
backendUrl()
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()
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
getEnv(name): string;returns an env variable from the craft/.env file. All env variables need to start with VITE_ except ENDPOINT_URL, CRAFT_WEB_URL and FRONTEND_URL
Parameters
name
"ENDPOINT_URL"
Returns
string
Call Signature
getEnv(name): string;Parameters
name
"CRAFT_WEB_URL"
Returns
string
Call Signature
getEnv(name): string;Parameters
name
"FRONTEND_URL"
Returns
string
Call Signature
getEnv(name): string | null;Parameters
name
string
Returns
string | null
getGlobalStore()
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()
getPlugin(name): Plugin | null;Get a Plugin by name
Parameters
name
string
Returns
Plugin | null
query()
query(
query,
variables?,
opts?): Promise<unknown>;Run a GraphQl Query
Parameters
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?
Returns
Promise<unknown>
toRequest()
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