UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

41 lines 1.56 kB
/** * @typedef {{ * verified: boolean; // Whether the domain is verified. * domain: string|null|true|string[]; // The detected domain from the request. * isStaticPath: boolean // Whether the request matches a static path. * }} DomainResult */ /** * @function domainValidator * * Validates the request's domain and optionally checks if the request is for a static path. * This is useful for filtering requests by origin or allowing access from specific domains only. * Also detects if Firebase is running in emulator mode, which bypasses domain validation. * * @param {import('express').Request} req - The Express request object. * - `req.url`: Full URL path. * - `req.headers`: Expected to contain 'host', 'x-forwarded-host', etc. * @param {Record<string, any>} cfg - Configuration object. * @property {string|string[]} cfg.domain - The allowed domain(s) to validate against. * @property {string[]} [cfg.staticPath] - Optional list of static paths to validate. * * @returns {DomainResult} * @deprecated * * @example * const result = domainValidator(req, { * domain: ['example.com', 'sub.example.com'], * staticPath: ['/assets/', '/static/'] * }); * * if (result.verified) { * console.log('Domain OK:', result.domain); * } */ export default function domainValidator(req: import("express").Request, cfg: Record<string, any>): DomainResult; export type DomainResult = { verified: boolean; domain: string | null | true | string[]; isStaticPath: boolean; }; //# sourceMappingURL=domainValidator.d.mts.map