mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-03 22:32:42 +00:00
⚙️ refactor: brotli asset serving behind a feature toggle (#13641)
This commit is contained in:
parent
db863e75e3
commit
346ebea2d9
3 changed files with 66 additions and 4 deletions
|
|
@ -6,9 +6,10 @@ const oneDayInSeconds = 24 * 60 * 60;
|
|||
|
||||
const sMaxAge = process.env.STATIC_CACHE_S_MAX_AGE || oneDayInSeconds;
|
||||
const maxAge = process.env.STATIC_CACHE_MAX_AGE || oneDayInSeconds * 2;
|
||||
const isEnabled = (value) => value === true || String(value).toLowerCase() === 'true';
|
||||
|
||||
/**
|
||||
* Creates an Express static middleware with optional gzip compression and configurable caching
|
||||
* Creates an Express static middleware with optional precompressed asset serving and configurable caching
|
||||
*
|
||||
* @param {string} staticPath - The file system path to serve static files from
|
||||
* @param {Object} [options={}] - Configuration options
|
||||
|
|
@ -18,6 +19,7 @@ const maxAge = process.env.STATIC_CACHE_MAX_AGE || oneDayInSeconds * 2;
|
|||
*/
|
||||
function staticCache(staticPath, options = {}) {
|
||||
const { noCache = false, skipGzipScan = false } = options;
|
||||
const enableBrotli = isEnabled(process.env.ENABLE_STATIC_ASSET_BROTLI);
|
||||
|
||||
const setHeaders = (res, filePath) => {
|
||||
if (process.env.NODE_ENV?.toLowerCase() !== 'production') {
|
||||
|
|
@ -51,8 +53,8 @@ function staticCache(staticPath, options = {}) {
|
|||
});
|
||||
} else {
|
||||
return expressStaticGzip(staticPath, {
|
||||
enableBrotli: false,
|
||||
orderPreference: ['gz'],
|
||||
enableBrotli,
|
||||
orderPreference: enableBrotli ? ['br', 'gz'] : ['gz'],
|
||||
setHeaders,
|
||||
index: false,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue