Enable extensions cache (#14499)

* enable caching for extension assets with ASSETS_CACHE_TTL setting

* simplify implementation
This commit is contained in:
Clayton Gulick
2022-07-19 10:51:32 -05:00
committed by GitHub
parent f9826afd87
commit ec77b0a203

View File

@@ -5,6 +5,9 @@ import { getExtensionManager } from '../extensions';
import { respond } from '../middleware/respond';
import { depluralize, isAppExtension } from '@directus/shared/utils';
import { Plural } from '@directus/shared/types';
import ms from 'ms';
import env from '../env';
import { getCacheControlHeader } from '../utils/get-cache-headers';
const router = Router();
@@ -47,7 +50,11 @@ router.get(
}
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
res.setHeader('Cache-Control', 'no-store');
if (env.EXTENSIONS_CACHE_TTL) {
res.setHeader('Cache-Control', getCacheControlHeader(req, ms(env.EXTENSIONS_CACHE_TTL as string)));
} else {
res.setHeader('Cache-Control', 'no-store');
}
res.setHeader('Vary', 'Origin, Cache-Control');
res.end(extensionSource);
})