UNPKG

tiny-server-essentials

Version:

A good utility toolkit to unify Express v5 and Socket.IO v4 into a seamless development experience with modular helpers, server wrappers, and WebSocket tools.

82 lines 3.22 kB
export default TinyWebInstance; /** * A strict web server wrapper that accepts only Node.js HTTP or HTTPS servers. */ declare class TinyWebInstance { /** * Creates a new TinyWebInstance bound to a Node.js HTTP or HTTPS server. * * @param {HttpServer | HttpsServer} server - A valid instance of http.Server or https.Server. * * @throws {Error} If `server` is not an instance of http.Server or https.Server. */ constructor(server: HttpServer | HttpsServer); /** * @type {HttpServer | HttpsServer} */ server: HttpServer | HttpsServer; /** * Returns the current Http server instance. * * @returns {HttpServer | HttpsServer} The active Http server. */ getServer(): HttpServer | HttpsServer; /** * Registers a domain string into the internal domain list. * * This can be used for domain-based routing, validation, or matching logic. * * @param {string} domain - The domain name to be registered (e.g., 'example.com'). * @throws {Error} If the domain is not a string. */ addDomain(domain: string): void; /** * Removes a domain string from the internal domain list. * * Throws an error if the domain is not registered. * * @param {string} domain - The domain name to be removed (e.g., 'example.com'). * @throws {Error} If the domain is not a string. * @throws {Error} If the domain is not found in the list. */ removeDomain(domain: string): void; /** * Returns a shallow clone of the internal domain list. * * This ensures the original list remains immutable from the outside. * * @returns {string[]} A cloned array containing all registered domain names. */ getDomains(): string[]; /** * Removes the port number from an IPv4, IPv6, or hostname. * * @param {string} host - The raw host string possibly including a port. * @returns {string} The host string without any port. */ stripPort(host: string): string; /** * Determines whether the specified host is allowed based on the registered domain list. * * Performs a strict comparison between the cleaned host and each stored domain. * The special value `'0.0.0.0'` acts as a wildcard, allowing any host to match. * To allow all hosts, ensure that `'0.0.0.0'` is included in the domain list. * * @param {string} host - The host to check (e.g., 'example.com', '192.168.0.1:8080'). * @returns {boolean} Returns `true` if the host matches any registered domain; otherwise, `false`. */ canDomain(host: string): boolean; /** * Checks whether a given host string matches a registered domain. * * This performs a strict comparison against all domains stored internally. * * @param {string} host - The host value to check (e.g., 'example.com', '192.168.0.1:8080'). * @returns {boolean} `true` if the host matches any registered domain, otherwise `false`. */ hasDomain(host: string): boolean; #private; } import { Server as HttpServer } from 'http'; import { Server as HttpsServer } from 'https'; //# sourceMappingURL=TinyWebInstance.d.mts.map