Files
habitica/website/server/controllers/api-v3/i18n.js
Matteo Pagliazzi e5f1f3b279 Improve i18n caching (#12030)
* fix indentation

* wip: cache i18n responses

* cache i18n browser script to disk

* typos

* misc fixes
2020-05-05 20:31:33 +02:00

37 lines
894 B
JavaScript

import nconf from 'nconf';
import {
BROWSER_SCRIPT_CACHE_PATH,
geti18nBrowserScript,
} from '../../libs/i18n';
const IS_PROD = nconf.get('IS_PROD');
const api = {};
/**
* @api {get} /api/v3/i18n/browser-script Returns the i18n JS script.
* @apiDescription Returns the i18n JS script to make
* all the i18n strings available in the browser under window.i18n.strings.
* Does not require authentication.
* @apiName i18nBrowserScriptGet
* @apiGroup i18n
*/
api.geti18nBrowserScript = {
method: 'GET',
url: '/i18n/browser-script',
async handler (req, res) {
if (IS_PROD) {
res.sendFile(`${BROWSER_SCRIPT_CACHE_PATH}${req.language}.js`);
} else {
res.set({
'Content-Type': 'application/javascript',
});
const jsonResString = geti18nBrowserScript(req.language);
res.status(200).send(jsonResString);
}
},
};
export default api;