CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-sveltejs--kit

Web framework for Svelte with SSR, file-based routing, load functions, form actions, and API endpoints

Pending
Overview
Eval results
Files

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

Install with Tessl CLI

npx tessl i tessl/npm-sveltejs--kit

docs

index.md

tile.json