From 9adaccd0366ce93ed1685aecc288bf5a238d3a26 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 10 Aug 2020 10:22:47 -0400 Subject: [PATCH] feat: +assetBaseUrl, -l10BaseUrl, -requireBaseUrl Additional base URLs were necessary for benchpress and translator, and in order to not clutter the API response with needless one- time use base URLs, I decided to use a single base that is used by all of the services, assetBaseUrl. --- public/src/ajaxify.js | 2 +- public/src/modules/translator.js | 6 +++--- public/src/require-config.js | 2 +- src/controllers/api.js | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 41304d1788..0f8668858a 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -328,7 +328,7 @@ $(document).ready(function () { }; ajaxify.loadTemplate = function (template, callback) { - require([config.relative_path + '/assets/templates/' + template + '.js'], callback, function (err) { + require([config.assetBaseUrl + '/templates/' + template + '.js'], callback, function (err) { console.error('Unable to load template: ' + template); throw err; }); diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index d6c32781ad..3e6981dba8 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -2,7 +2,7 @@ (function (factory) { function loadClient(language, namespace) { - return Promise.resolve(jQuery.getJSON(config.l10nBaseUrl + '/' + language + '/' + namespace + '.json?' + config['cache-buster'])); + return Promise.resolve(jQuery.getJSON([config.assetBaseUrl, 'language', language, namespace].join('/') + '.json?' + config['cache-buster'])); } var warn = function () { console.warn.apply(console, arguments); }; if (typeof define === 'function' && define.amd) { @@ -605,7 +605,7 @@ } var originalSettings = assign({}, jQuery.timeago.settings.strings); - jQuery.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '-short.js').done(function () { + jQuery.getScript(config.assetBaseUrl + '/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '-short.js').done(function () { adaptor.timeagoShort = assign({}, jQuery.timeago.settings.strings); jQuery.timeago.settings.strings = assign({}, originalSettings); toggle(); @@ -620,7 +620,7 @@ delete adaptor.timeagoShort; var languageCode = utils.userLangToTimeagoCode(config.userLang); - jQuery.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '.js').done(callback); + jQuery.getScript(config.assetBaseUrl + '/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '.js').done(callback); }, prepareDOM: function prepareDOM() { diff --git a/public/src/require-config.js b/public/src/require-config.js index 4e919329e4..00607597e2 100644 --- a/public/src/require-config.js +++ b/public/src/require-config.js @@ -1,7 +1,7 @@ 'use strict'; require.config({ - baseUrl: config.requireBaseUrl, + baseUrl: config.assetBaseUrl + '/src/modules', waitSeconds: 0, urlArgs: config['cache-buster'], paths: { diff --git a/src/controllers/api.js b/src/controllers/api.js index 4f1ac43b64..e10c935d80 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -19,8 +19,7 @@ apiController.loadConfig = async function (req) { let config = { relative_path: nconf.get('relative_path'), upload_url: nconf.get('upload_url'), - requireBaseUrl: `${nconf.get('relative_path')}/assets/src/modules`, - l10nBaseUrl: `${nconf.get('relative_path')}/assets/language`, + assetBaseUrl: `${nconf.get('relative_path')}/assets`, siteTitle: validator.escape(String(meta.config.title || meta.config.browserTitle || 'NodeBB')), browserTitle: validator.escape(String(meta.config.browserTitle || meta.config.title || 'NodeBB')), titleLayout: (meta.config.titleLayout || '{pageTitle} | {browserTitle}').replace(/{/g, '{').replace(/}/g, '}'),