Skip to content

crelte / server / CrelteServerRequest

Class: CrelteServerRequest

Constructors

Constructor

ts
new CrelteServerRequest(req, opts): CrelteServerRequest;

Parameters

req

ServerRequest

opts

CrelteServerRequestOptions

Returns

CrelteServerRequest

Properties

req

ts
req: ServerRequest;

The current request ServerRequest

Accessors

cookies

Get Signature

ts
get cookies(): Cookies;

Get the Cookies instance

Returns

Cookies


graphQl

Get Signature

ts
get graphQl(): Queries;

Get the Queries instance

Returns

Queries


preferredLanguages

Get Signature

ts
get preferredLanguages(): string[];

The languages which are preferred by the user

Returns

string[]


site

Get Signature

ts
get site(): Site;

Easy access to this.req.site

Note

The site might not always match with the current route but be the site default site or one that matches the users language.

Returns

Site


sites

Get Signature

ts
get sites(): Site[];

The sites which are available

Returns

Site[]

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

For the origin the FRONTEND_URL env variable is used

Parameters

path?

string

Returns

URL


getEnv()

Call Signature

ts
getEnv(name): string;

returns an env variable from the craft/.env file.

Parameters
name

"ENDPOINT_URL"

Returns

string

Call Signature

ts
getEnv(name): string;

returns an env variable from the craft/.env file.

Parameters
name

"CRAFT_WEB_URL"

Returns

string

Call Signature

ts
getEnv(name): string;

returns an env variable from the craft/.env file.

Parameters
name

"FRONTEND_URL"

Returns

string

Call Signature

ts
getEnv(name): string | null;

returns an env variable from the craft/.env file.

Parameters
name

string

Returns

string | null


preferredSite()

ts
preferredSite(): Site | null;

Returns a site which is preferred based on the users language

Returns null if no site could be determined

Returns

Site | null


primarySite()

ts
primarySite(): Site;

Returns the primary site

Returns

Site


query()

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

Run a Queries 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>