import type { Request, Response } from 'express'; import type { ImportMap } from './ImportMap.js'; import type { PackageJson } from './PackageJson.js'; import type { RenderedRoute } from './Route.js'; import type { Session } from './Session.js'; /** * A custom server render function that can be used to override the default HTML response. */ export type RenderFunction = (options: RenderFunctionOptions) => Promise | RenderFunctionResult; /** * Input for a `serverEntry`/`renderScript` custom server render function. */ export interface RenderFunctionOptions { /** * Info about the current app session. * @deprecated Use top-level properties instead (see comment on `requestInfo` for reasoning). * Please talk to the team if you need a property that isn't listed. */ session: Session; /** Path to the root of the app package */ appPath: string; /** Processed route being rendered */ route: RenderedRoute; /** Base URL of the app server, including port */ baseUrl: string; /** `package.json` for the app */ definition: PackageJson; /** Import map that will be used by the app at runtime (will be injected into a returned HTML response) */ importMap: ImportMap; /** URL for the Cloudpack overlay script bundle (will be injected into a returned HTML response) */ overlayScript?: string; /** Additional script bundle URLs from `route.entry` (will be injected into a returned HTML response) */ entryScripts?: string[]; /** Inline script tag contents used for Cloudpack initialization (will be injected into a returned HTML response) */ inlineScripts?: string[]; /** * Subset of properties from the current HTTP request (talk to the team if you need something additional). * * Previously, we passed the original `Request` object to the render function, but going forward * (with the `enableSSR` feature and eventually by default), the renderer will run in a separate * process, and `Request`s aren't serializable. */ requestInfo: RequestInfo; /** * Current request * @deprecated Use `requestInfo` instead (see comment there for details). * Please talk to the team if you need a property that isn't listed there. */ req: Request; /** * Current response * @deprecated Return properties from the function instead. Please talk to the team if you need * to do something that isn't supported by `RenderFunctionResult`. */ res: Response; } /** * Subset of properties from the current HTTP request (talk to the team if you need something additional). */ export interface RequestInfo extends Pick { /** Whether this is an encrypted connection per `req.socket.encrypted` */ isEncrypted: boolean; } /** * The complete expected result of the `serverEntry`/`renderScript` custom server render function. */ export interface ExpandedRenderFunctionResult { /** * Response body. If non-HTML, `contentType` must be set. * `content` is required except for status codes such as 304 that don't have a body. * (Support for other value types could be added in the future if needed.) */ content?: string | object; /** Standard HTTP status code - https://developer.mozilla.org/en-US/docs/Web/HTTP/Status */ statusCode: number; /** MIME type for the response - https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types */ contentType: string; /** Extra headers to include in the response */ headers?: Record; /** * For HTML responses in advanced scenarios only: set to `false` to prevent Cloudpack from * injecting `entry` scripts, default scripts, or the import map into the returned content. * If this is `false`, it's assumed you've manually handled injecting any necessary scripts * from the passed options. * @default true */ injectScripts?: boolean; } /** * The expected result of the `serverEntry`/`renderScript` custom server render function. * * - If a string, it's assumed to be the HTML content. * - If an object and the `content` is non-HTML, `contentType` must be set. * `content` is required except for status codes such as 304 that don't have a body. * - (Returning `null` is deprecated.) */ export type RenderFunctionResult = string | null | Partial; /** * `serverEntry` function options with `enableSSR` feature on. */ export type ServerEntryFunctionOptions = Omit; /** * `serverEntry` function result with `enableSSR` feature on. * Right now this can return the same values, except for `null` since that indicates the renderer * fully handled the request, and the worker-based renderer can't do that because it doesn't have * access to the response object. * * Please talk to the team if you need additional properties or other custom response behavior. */ export type ServerEntryFunctionResult = Exclude; /** * `serverEntry` function with `enableSSR` feature on. */ export type ServerEntryFunction = (options: ServerEntryFunctionOptions) => Promise | ServerEntryFunctionResult; //# sourceMappingURL=RenderFunction.d.ts.map