/** Kitten Server. Copyright © 2021-present, Aral Balkan Small Technology Foundation License: AGPL version 3.0. */ import { WebSocketServer } from 'ws'; import AutomaticUpdates from './AutomaticUpdates.ts'; import AppRepository from './AppRepository.ts'; import http from 'node:http'; import type { KittenPolka } from './types/index.ts'; import type { RouteDictionary } from './Routes.ts'; export type ServerOptions = { domains?: Array; domain?: string; port?: number | boolean; aliases?: string | Array; open?: boolean; 'working-directory'?: string; 'domain-token'?: string; 'small-web-host-domain'?: string; settingsPath?: string; domainToken?: string; smallWebHostDomain?: string; minVersion?: string; ipv4?: boolean; ipv6?: boolean; ipOnly?: boolean; }; export default class Server { /** Singleton instance. */ static instance: Server; static isBeingConstructedViaFactoryMethod: boolean; options: ServerOptions; port: number; domain: string | undefined; open: boolean | undefined; app: KittenPolka; projectUploadsPath: string | undefined; appRepository: AppRepository | undefined; automaticUpdates: AutomaticUpdates | undefined; routes: Record | undefined; kittenSettingsApplicationRoutes: Record | undefined; server: any; wss: WebSocketServer | undefined; /** Singleton factory method. Await this instead of calling `new Server(…)` and `await server.initialise()`` manually. Returns a promise for a reference to the server singleton, that resolves immediately if it exists, and otherwise resolves once it is created and initialised. */ static getInstanceAsync(options: ServerOptions): Promise; /** Create server instance using passed options. */ constructor(); /** Create server instance using passed options. */ initialise(options: ServerOptions): Promise; /** Node http(s) upgrade event handler (https://nodejs.org/api/http.html#event-upgrade) Implementation based on express-websocket and tinyws, to keep some of the modern interface of tinyws (async/await syntax) while avoiding the client connection timeout issue in tinyws. (See https://codeberg.org/kitten/app/issues/113). */ upgradeHandler(request: http.IncomingMessage, socket: import('node:net').Socket, head: Buffer): any; }