import * as http from 'http'; import { Server } from 'http'; import express from 'express'; import { PluridPreserve, IsoMatcherRouteResult, PluridRoute, PluridRoutePlane, PluridRouterProperties } from '@plurid/plurid-data'; import { PluridReactComponent } from '@plurid/plurid-react'; import { Helmet } from 'react-helmet-async'; type PluridServerMiddleware = (request: express.Request, response: express.Response, next: express.NextFunction) => void; type ServerRequest = express.Request & { requestID: string; requestTime: number; }; type DebugLevels = 'none' | 'error' | 'warn' | 'info'; interface PluridServerOptions { /** To be used for logging. Default `Plurid Server` */ serverName: string; /** * The hostname of the server exposed to the internet, e.g. `example.com`, * to be used in plurid plane links. */ hostname: string; /** * To log or not to log to the console. */ quiet: boolean; /** * Debug levels. * * Production default: `error`. * Development default: `info` and above. */ debug: DebugLevels; /** * Use `gzip` compression for the response. Default `true`. */ compression: boolean; /** * Open in browser at start. */ open: boolean; /** * Name of the directory where the files (server and client) are bundled. */ buildDirectory: string; /** * Name of the directory where the assets files are bundled. */ assetsDirectory: string; /** * Directory of static assets (favicon, og-image, manifest, robots) served at * the URL root `/`. Empty string (the default) resolves to * `/public`; the mount is skipped if the directory does not * exist, so apps without a public directory are unaffected. The framework * points this at `source/public` during `plurid dev`. */ publicDirectory: string; /** * Default: `/gateway`. */ gatewayEndpoint: string; /** * Provide a `max-age` in milliseconds for http caching of the static serves. * This can also be a string accepted by the `ms` module. * * Default: 0. */ staticCache: number | string; /** * Routes to be ignored when serving the application (`GET`). */ ignore: string[]; /** * Name of the directory where the stills are gathered. */ stillsDirectory: string; stiller: PluridStillerOptions; /** * Install `SIGINT`/`SIGTERM` handlers that stop the server and call `process.exit`. * Defaults to `true` (convenient for the CLI). Set to `false` when EMBEDDING the server * in a host process you do not want it to terminate; then manage lifecycle via `stop()`. */ attachSignalHandlers: boolean; } type PluridServerPartialOptions = Partial; interface PluridServerService

{ name: string; Provider: P; properties?: PP; } interface PluridServerConfiguration { routes: PluridRoute[]; planes?: PluridRoutePlane[]; preserves: PluridPreserveReact[]; helmet: Helmet; styles?: string[]; middleware?: PluridServerMiddleware[]; exterior?: PluridReactComponent; shell?: PluridReactComponent; routerProperties?: Partial>; /** * Replace the internal plurid plane with a custom implementation. */ customPlane?: PluridReactComponent; /** * Services to be handled by the server. * * Supported: `GraphQL`, `Redux`, `Stripe`. */ services?: PluridServerService[]; options?: PluridServerPartialOptions; template?: PluridServerTemplateConfiguration; usePTTP?: boolean; pttpHandler?: PTTPHandler; elementqlEndpoint?: string; } type PTTPHandler = (path: string) => Promise; interface PluridServerTemplateConfiguration { htmlLanguage?: string; htmlAttributes?: Record; defaultStyle?: string; headScripts?: string[]; bodyScripts?: string[]; /** * The JavaScript vendor filepath to inject in the HTML template. * Default `'/vendor.js'`. * * A CDN link can be used for better caching. */ vendorScriptSource?: string; /** * The JavaScript filename to inject in the HTML template. */ mainScriptSource?: string; bodyAttributes?: Record; /** * The ID of the root element in the HTML template. */ root?: string; /** * Global variable name to be attached to window on the server-side * to preload plurid metastate. * * Default: `__PRELOADED_PLURID_METASTATE__` */ defaultPreloadedPluridMetastate?: string; minify?: boolean; /** * Favicon links injected into ``. A bare string is the primary icon * (`rel="icon"`); the object expands to icon / apple-touch-icon / sized / * mask-icon links plus a `theme-color` meta. Paths resolve against the served * public directory (see `PluridServerOptions.publicDirectory`). */ favicon?: string | { icon?: string; apple?: string; sizes?: Record; maskIcon?: string; themeColor?: string; }; /** * Web app manifest href, injected as ``. */ manifest?: string; /** * Static `` metadata injected AHEAD of the react-helmet-async output, * so per-route `` tags still override these defaults. */ head?: { title?: string; description?: string; meta?: Array<{ name?: string; property?: string; content: string; }>; links?: Array<{ rel: string; href: string; }>; }; /** * Override the built-in 500 error page HTML (sent on a render failure). */ errorHtml?: string; } interface PluridStillerOptions { /** * Recommended: `'networkidle0'` | `'networkidle2'` | `'load'`. * * Default: `'networkidle0'`. */ waitUntil: 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'; /** * Maximum navigation time in milliseconds, pass 0 to disable timeout. * * Default: 30000. */ timeout: number; /** * Routes to be ignored by the stilling process. */ ignore: string[]; } type PluridPreserveReact = PluridPreserve> | undefined, express.Request, express.Response>; interface PluridLiveServerOptions { server: string; } interface StillsGeneratorOptions { server: string; build: string; } declare class PluridServer { private routes; private planes; private preserves; private helmet; private styles; private middleware; private exterior; private shell; private routerProperties; private services; private options; private template; usePTTP: boolean; private pttpHandler; private elementqlEndpoint; private serverApplication; private server; private port; private stills; private isoMatcher; constructor(configuration: PluridServerConfiguration); private handleProcessSignal; private signalHandlersAttached; attachSignalHandlers(): void; detachSignalHandlers(): void; static analysis(pluridServer: PluridServer): { routes: PluridRoute[]; options: PluridServerOptions; }; start(port?: string | number): Server; stop(): void; handle(): { post: (path: string, ...handlers: express.RequestHandler[]) => express.Express; patch: (path: string, ...handlers: express.RequestHandler[]) => express.Express; put: (path: string, ...handlers: express.RequestHandler[]) => express.Express; delete: (path: string, ...handlers: express.RequestHandler[]) => express.Express; }; instance(): express.Express; private handleEndpoints; private handleGetRequest; private handlePTTPRequest; private ignoreGetRequest; private resolveMatchingPath; private resolvePreserve; private resolvePreserveAfterServe; private handleGateway; private renderApplication; /** * Build the static `` markup from the template config (favicon set, * manifest, default title / meta / links). Returns an empty string when none * are configured, so the head is byte-identical to before for existing apps. */ private buildStaticHead; private getContentAndStyles; private computeRequestTime; private handleOptions; private configureServer; private loadMiddleware; private open; private debugAllows; } declare class LiveServer { private options; private expressServer; private httpServer; private sockets; constructor(options?: Partial); private resolveOptions; private setupExpressServer; private setupHttpServer; start(): never; } declare class StillsGenerator { private options; constructor(options?: Partial); resolveOptions(options?: Partial): StillsGeneratorOptions; initialize(): Promise; } export { type DebugLevels, type PTTPHandler, LiveServer as PluridLiveServer, type PluridLiveServerOptions, type PluridPreserveReact, type PluridServerConfiguration, type PluridServerMiddleware, type PluridServerOptions, type PluridServerPartialOptions, type PluridServerService, type PluridServerTemplateConfiguration, type PluridStillerOptions, StillsGenerator as PluridStillsGenerator, type ServerRequest, PluridServer as default };