UNPKG

@adonisjs/inertia

Version:

Official Inertia.js adapter for AdonisJS

55 lines (54 loc) 1.67 kB
import { type Vite } from '@adonisjs/vite'; import type { PageObject, InertiaConfig } from './types.js'; /** * Server-side renderer for Inertia.js applications. * * Handles rendering Inertia pages on the server using either Vite's development * runtime API or production SSR bundles. * * @example * ```typescript * const renderer = new ServerRenderer(config, vite) * const { head, body } = await renderer.render(pageObject) * ``` */ export declare class ServerRenderer { #private; /** * Creates a new ServerRenderer instance. * * @param config - Inertia configuration object containing SSR settings * @param vite - Vite instance for development mode rendering and asset management * * @example * ```js * const renderer = new ServerRenderer(config, vite) * ``` */ constructor(config: InertiaConfig, vite: Vite); /** * Renders an Inertia page on the server. * * In development mode, uses Vite's Runtime API to execute the SSR entrypoint. * In production mode, imports and uses the pre-built SSR bundle. * * @param pageObject - The Inertia page object containing component, props, and metadata * @returns Promise resolving to an object with rendered head and body HTML * * @example * ```js * const pageObject = { * component: 'Home', * props: { user: { name: 'John' } }, * url: '/dashboard', * version: '1.0.0' * } * * const { head, body } = await renderer.render(pageObject) * ``` */ render(pageObject: PageObject<any>): Promise<{ head: string[]; body: string; }>; }