Skip to main content

$app/server

import {
	function command<Output>(fn: () => Output): RemoteCommand<void, Output> (+2 overloads)

Creates a remote command. When called from the browser, the function will be invoked on the server via a fetch call.

See Remote functions for full documentation.

command
,
function form<T>(fn: (data: FormData) => MaybePromise<T>): RemoteForm<T>

Creates a form object that can be spread onto a &#x3C;form> element.

See Remote functions for full documentation.

form
,
function getRequestEvent(): RequestEvent<AppLayoutParams<"/">, any>

Returns the current RequestEvent. Can be used inside server hooks, server load functions, actions, and endpoints (and functions called by them).

In environments without AsyncLocalStorage, this must be called synchronously (i.e. not after an await).

@since2.20.0
getRequestEvent
,
function prerender<Output>(fn: () => MaybePromise<Output>, options?: {
    inputs?: RemotePrerenderInputsGenerator<void>;
    dynamic?: boolean;
} | undefined): RemotePrerenderFunction<void, Output> (+2 overloads)

Creates a remote prerender function. When called from the browser, the function will be invoked on the server via a fetch call.

See Remote functions for full documentation.

prerender
,
function query<Output>(fn: () => MaybePromise<Output>): RemoteQueryFunction<void, Output> (+2 overloads)

Creates a remote query. When called from the browser, the function will be invoked on the server via a fetch call.

See Remote functions for full documentation.

query
,
function read(asset: string): Response

Read the contents of an imported asset from the filesystem

@examplejs import { read } from '$app/server'; import somefile from './somefile.txt'; const asset = read(somefile); const text = await asset.text();
@since2.4.0
read
} from '$app/server';

command

Disponible depuis la version 2.27

Crée une commande distante. Lorsqu’exécutée sur le navigateur, la fonction sera invoquée sur le serveur via un appel fetch.

Voir la section sur les fonctions distantes pour lire la documentation complète.

function command<Output>(
	fn: () => Output
): RemoteCommand<void, Output>;
function command<Input, Output>(
	validate: 'unchecked',
	fn: (arg: Input) => Output
): RemoteCommand<Input, Output>;
function command<Schema extends StandardSchemaV1, Output>(
	validate: Schema,
	fn: (arg: StandardSchemaV1.InferOutput<Schema>) => Output
): RemoteCommand<
	StandardSchemaV1.InferInput<Schema>,
	Output
>;

form

Disponible depuis la version 2.27

Crée un objet de formulaire pouvant être “étalé” sur un élément <form>

Voir la section sur les fonctions distantes pour lire la documentation complète.

function form<T>(
	fn: (data: FormData) => MaybePromise<T>
): RemoteForm<T>;

getRequestEvent

Disponible depuis la version 2.20.0

Renvoie l’objet RequestEvent courant. Peut être utilisé dans les hooks de serveur, les fonctions load de serveur, les actions, et les endpoints (et dans les fonctions exécutées par ceux-ci).

Dans les environnements ne possédant pas de AsyncLocalStorage, cette méthode doit être appelée de manière synchrone (c’est-à-dire pas après un await).

function getRequestEvent(): RequestEvent<
	AppLayoutParams<'/'>,
	any
>;

prerender

Disponible depuis la version 2.27

Crée une fonction de pré-rendu distante. Lorsqu’exécutée sur le navigateur, la fonction sera invoquée sur le serveur via un appel fetch.

Voir la section sur les fonctions distantes pour lire la documentation complète.

function prerender<Output>(
	fn: () => MaybePromise<Output>,
	options?:
		| {
				inputs?: RemotePrerenderInputsGenerator<void>;
				dynamic?: boolean;
		  }
		| undefined
): RemotePrerenderFunction<void, Output>;
function prerender<Input, Output>(
	validate: 'unchecked',
	fn: (arg: Input) => MaybePromise<Output>,
	options?:
		| {
				inputs?: RemotePrerenderInputsGenerator<Input>;
				dynamic?: boolean;
		  }
		| undefined
): RemotePrerenderFunction<Input, Output>;
function prerender<Schema extends StandardSchemaV1, Output>(
	schema: Schema,
	fn: (
		arg: StandardSchemaV1.InferOutput<Schema>
	) => MaybePromise<Output>,
	options?:
		| {
				inputs?: RemotePrerenderInputsGenerator<
					StandardSchemaV1.InferInput<Schema>
				>;
				dynamic?: boolean;
		  }
		| undefined
): RemotePrerenderFunction<
	StandardSchemaV1.InferInput<Schema>,
	Output
>;

query

Disponible depuis la version 2.27

Crée une query distante. Lorsqu’exécutée sur le navigateur, la fonction sera invoquée sur le serveur via un appel fetch.

Voir la section sur les fonctions distantes pour lire la documentation complète.

function query<Output>(
	fn: () => MaybePromise<Output>
): RemoteQueryFunction<void, Output>;
function query<Input, Output>(
	validate: 'unchecked',
	fn: (arg: Input) => MaybePromise<Output>
): RemoteQueryFunction<Input, Output>;
function query<Schema extends StandardSchemaV1, Output>(
	schema: Schema,
	fn: (
		arg: StandardSchemaV1.InferOutput<Schema>
	) => MaybePromise<Output>
): RemoteQueryFunction<
	StandardSchemaV1.InferInput<Schema>,
	Output
>;

read

Disponible depuis la version 2.4.0

Lit le contenu d’un asset importé depuis le système de fichiers.

import { function read(asset: string): Response

Read the contents of an imported asset from the filesystem

@examplejs import { read } from '$app/server'; import somefile from './somefile.txt'; const asset = read(somefile); const text = await asset.text();
@since2.4.0
read
} from '$app/server';
import const somefile: stringsomefile from './somefile.txt'; const const asset: Responseasset = function read(asset: string): Response

Read the contents of an imported asset from the filesystem

@examplejs import { read } from '$app/server'; import somefile from './somefile.txt'; const asset = read(somefile); const text = await asset.text();
@since2.4.0
read
(const somefile: stringsomefile);
const const text: stringtext = await const asset: Responseasset.Body.text(): Promise<string>text();
function read(asset: string): Response;

Modifier cette page sur Github llms.txt

précédent suivant