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.

37 lines 1.58 kB
/** * @function fileCache * * Sends a stringified file as a response with caching, security headers, and optional metadata. * If `data.file` is not a string, the request is passed to the next middleware. * * @param {import('express').Response} res - Express response object. * @param {import('express').NextFunction} next - Express next middleware function. * @param {object} data - Configuration object for the file response. * @param {string} [data.file] - The content of the file to send (must be a string). * @param {number} [data.fileMaxAge] - Max age in seconds for cache expiration. * @param {string} [data.date] - A date string used for the `Last-Modified` header. * @param {string} [data.timezone="Universal"] - Timezone for `moment.tz()`. * @param {string} [data.contentType="application/javascript"] - MIME type for the response. * @deprecated * * @example * import fileCache from './fileCache.mjs'; * * app.get('/my-script.js', (req, res, next) => { * const content = fs.readFileSync('./public/my-script.js', 'utf8'); * fileCache(res, next, { * file: content, * fileMaxAge: 3600, * date: fs.statSync('./public/my-script.js').mtime, * contentType: 'application/javascript' * }); * }); */ export default function fileCache(res: import("express").Response, next: import("express").NextFunction, data: { file?: string | undefined; fileMaxAge?: number | undefined; date?: string | undefined; timezone?: string | undefined; contentType?: string | undefined; }): void; //# sourceMappingURL=fileCache.d.mts.map