or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

examples

edge-cases.mdreal-world-scenarios.md
index.md
tile.json

server-utilities.mddocs/reference/

Server Utilities

Server-only utilities for reading assets and accessing request context.

Capabilities

Read Asset

/**
 * Read imported asset from filesystem
 * @param asset - Asset identifier (from import)
 * @returns Response with file contents
 * @since 2.4.0
 */
function read(asset: string): Response;

Usage:

// +server.ts
import { read } from '$app/server';
import dataFile from '$lib/data.json?url';

export async function GET() {
  return read(dataFile);
}

Get Request Event

/**
 * Get current RequestEvent in synchronous server context
 * @returns Current RequestEvent
 * @since 2.20.0
 */
function getRequestEvent(): RequestEvent;

Usage:

import { getRequestEvent } from '$app/server';

function someUtility() {
  const event = getRequestEvent();
  const userId = event.locals.user?.id;
  return userId;
}

Notes

  • Both functions are server-only (error if called on client)
  • read() requires asset imported with ?url suffix
  • getRequestEvent() only works during request handling (not at module level)
  • Useful in utility functions that need request context