import React from 'react'; import { Application, Request, Response } from 'express'; import { Configuration } from 'webpack'; import WebSocketService from './websocket'; export interface SessionState { sessionToken: string; [key: string]: any; } export declare type SessionRequest = Request & { session: SessionState; }; export interface OrisonSettings { /** * returns the default session state created for new sessions */ sessionStateGenerator: (req: Request) => Omit; /** * returns the webpack configuration for compilation, given the default one */ rewebpack?: (options: Configuration, transformer?: 'server' | 'client') => Configuration; /** * true if the server is in production mode */ production?: boolean; /** * a list of routes which will be rendered server-side only and will not be hydrated client-side */ skipHydration?: string[]; /** * whether or not to statically render the master page and its child page before passing it to the `App` on the server-side. * If this is `true`, the body passed to the `App` is a `div` containing the static HTML string. * If this is `false,` the body passed is a `React.ReactElement` containing the React component for the body. * Note that if this is `false` the body will be statically rendered twice: one phase for the server-side CSS generation, and another phase for the App. * * @default true */ preRenderBody?: boolean; } export declare class OrisonServer { private server; private sessions; private settings; private modules; private pageDependencies; private webSocketService; constructor(); setModuleDefinition(path: string, module: any): void; setModuleDependencies(path: string, deps: string[]): void; getSettings(): OrisonSettings | null; getSessions(): SessionState[]; getWebSocketService(): WebSocketService; /** * Initializes the Orison server instance using the given settings, builds the server and client files with Webpack, initializes all API routes, and creates all Express request listeners. * * @param settings The settings for the Orison server. */ configure(settings: OrisonSettings): Promise; /** * @returns The Express request handler used by Orison. */ getRequestListener(): Application; /** * Starts the server using the default `listen` function using `express`. * * @param port The TCP port to bind the server to. */ start(port: number): void; } export declare type OrisonPage = React.FC & { getServerSideProps?: (req: SessionRequest, res: Response) => T | Promise | void | Promise; }; export interface OrisonAppProps { head: React.ReactNode; body: React.ReactNode; } export interface OrisonRenderer { /** * Renders a React element to an HTML string. */ render: (element: React.ReactElement) => string; } export declare type OrisonApp = (renderer: OrisonRenderer, props: OrisonAppProps) => string;