From 621797fbf4b69f47f40de362de7fdb1101a944b2 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 17 Dec 2024 13:48:05 -0300 Subject: [PATCH] chore: configureCDN --- apps/meteor/server/main.ts | 3 ++ apps/meteor/server/startup/configureCDN.ts | 32 +++++++++++++++++ .../server/startup/settingsOnLoadCdnPrefix.js | 35 ------------------- 3 files changed, 35 insertions(+), 35 deletions(-) create mode 100644 apps/meteor/server/startup/configureCDN.ts delete mode 100644 apps/meteor/server/startup/settingsOnLoadCdnPrefix.js diff --git a/apps/meteor/server/main.ts b/apps/meteor/server/main.ts index 396fc18a3c754..a63ebb015c31f 100644 --- a/apps/meteor/server/main.ts +++ b/apps/meteor/server/main.ts @@ -1,5 +1,6 @@ import './tracing'; import './models/startup'; + /** * ./settings uses top level await, in theory the settings creation * and the startup should be done in parallel @@ -11,6 +12,7 @@ import { configureLogLevel } from './configureLogLevel'; import { registerServices } from './services/startup'; import { startup } from './startup'; import { configureBoilerplate } from './startup/configureBoilerplate'; +import { configureCDN } from './startup/configureCDN'; import { configureDirectReply } from './startup/configureDirectReply'; import { configureIRC } from './startup/configureIRC'; import { configureFederation } from './startup/settings'; @@ -40,6 +42,7 @@ await Promise.all([configureLoginServices(), startFederationService()]); await Promise.all([ configureAssets(settings), + configureCDN(settings), configurePushNotifications(settings), configureBoilerplate(settings), configureDirectReply(settings), diff --git a/apps/meteor/server/startup/configureCDN.ts b/apps/meteor/server/startup/configureCDN.ts new file mode 100644 index 0000000000000..b6d1aed4ae73a --- /dev/null +++ b/apps/meteor/server/startup/configureCDN.ts @@ -0,0 +1,32 @@ +import { WebAppInternals } from 'meteor/webapp'; + +import type { ICachedSettings } from '../../app/settings/server/CachedSettings'; + +export async function configureCDN(settings: ICachedSettings): Promise { + settings.change('CDN_PREFIX', (value) => { + const useForAll = settings.get('CDN_PREFIX_ALL'); + if (value && useForAll) { + WebAppInternals.setBundledJsCssPrefix(value); + } + }); + + settings.change('CDN_JSCSS_PREFIX', (value) => { + const useForAll = settings.get('CDN_PREFIX_ALL'); + if (value && typeof value === 'string' && value.trim() && !useForAll) { + WebAppInternals.setBundledJsCssPrefix(value); + } + }); + + const cdnValue = settings.get('CDN_PREFIX'); + const useForAll = settings.get('CDN_PREFIX_ALL'); + const cdnJsCss = settings.get('CDN_JSCSS_PREFIX'); + if (cdnValue && typeof cdnValue === 'string' && cdnValue.trim()) { + if (useForAll) { + WebAppInternals.setBundledJsCssPrefix(cdnValue); + return; + } + if (cdnJsCss && typeof cdnJsCss === 'string' && cdnJsCss.trim()) { + WebAppInternals.setBundledJsCssPrefix(cdnJsCss); + } + } +} diff --git a/apps/meteor/server/startup/settingsOnLoadCdnPrefix.js b/apps/meteor/server/startup/settingsOnLoadCdnPrefix.js deleted file mode 100644 index 9dc8ef164b866..0000000000000 --- a/apps/meteor/server/startup/settingsOnLoadCdnPrefix.js +++ /dev/null @@ -1,35 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { WebAppInternals } from 'meteor/webapp'; - -import { settings } from '../../../settings/server'; - -function testWebAppInternals(fn) { - typeof WebAppInternals !== 'undefined' && fn(WebAppInternals); -} -settings.change('CDN_PREFIX', (value) => { - const useForAll = settings.get('CDN_PREFIX_ALL'); - if (value && typeof value.valueOf() === 'string' && value.trim() && useForAll) { - return testWebAppInternals((WebAppInternals) => WebAppInternals.setBundledJsCssPrefix(value)); - } -}); - -settings.change('CDN_JSCSS_PREFIX', (value) => { - const useForAll = settings.get('CDN_PREFIX_ALL'); - if (value && typeof value.valueOf() === 'string' && value.trim() && !useForAll) { - return testWebAppInternals((WebAppInternals) => WebAppInternals.setBundledJsCssPrefix(value)); - } -}); - -Meteor.startup(() => { - const cdnValue = settings.get('CDN_PREFIX'); - const useForAll = settings.get('CDN_PREFIX_ALL'); - const cdnJsCss = settings.get('CDN_JSCSS_PREFIX'); - if (cdnValue && typeof cdnValue.valueOf() === 'string' && cdnValue.trim()) { - if (useForAll) { - return testWebAppInternals((WebAppInternals) => WebAppInternals.setBundledJsCssPrefix(cdnValue)); - } - if (cdnJsCss && typeof cdnJsCss.valueOf() === 'string' && cdnJsCss.trim()) { - return testWebAppInternals((WebAppInternals) => WebAppInternals.setBundledJsCssPrefix(cdnJsCss)); - } - } -});