Skip to main content

$app/server

import { function getRequestEvent(): RequestEvent<Partial<Record<string, string>>, string | null>

Returns the current RequestEvent. Can be used inside handle, load and actions (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 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';

getRequestEvent

自可用以来 2.20.0

¥Available since 2.20.0

返回当前 RequestEvent。可以在 handleload 和操作(以及它们调用的函数)中使用。

¥Returns the current RequestEvent. Can be used inside handle, load and actions (and functions called by them).

在没有 AsyncLocalStorage 的环境中,必须同步调用此函数(即不在 await 之后)。

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

function getRequestEvent(): RequestEvent<
	Partial<Record<string, string>>,
	string | null
>;

read

自 2.4.0 起可用

¥Available since 2.4.0

从文件系统读取导入资源的内容

¥Read the contents of an imported asset from the filesystem

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;
上一页 下一页