2017-08-24 23:54:02 +02:00
|
|
|
const config = require('./config');
|
|
|
|
const layout = require('./layout');
|
2018-08-08 00:40:17 +02:00
|
|
|
const assets = require('../common/assets');
|
2018-11-20 15:50:59 +01:00
|
|
|
const getTranslator = require('./locale');
|
2018-11-20 21:07:47 +01:00
|
|
|
const { getFxaConfig } = require('./fxa');
|
2022-08-13 02:25:19 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2017-08-24 23:54:02 +02:00
|
|
|
|
2018-11-20 21:07:47 +01:00
|
|
|
module.exports = async function(req) {
|
2022-08-13 02:25:19 +02:00
|
|
|
const locale = (() => {
|
|
|
|
if (config.custom_locale != '' && fs.existsSync(path.join(__dirname,'../public/locales',config.custom_locale))) {
|
|
|
|
return config.custom_locale;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return req.language || 'en-US';
|
|
|
|
}
|
|
|
|
})();
|
2018-11-20 21:07:47 +01:00
|
|
|
let authConfig = null;
|
2019-03-14 21:17:47 +01:00
|
|
|
let robots = 'none';
|
|
|
|
if (req.route && req.route.path === '/') {
|
|
|
|
robots = 'all';
|
|
|
|
}
|
2018-11-20 21:07:47 +01:00
|
|
|
if (config.fxa_client_id) {
|
|
|
|
try {
|
|
|
|
authConfig = await getFxaConfig();
|
|
|
|
authConfig.client_id = config.fxa_client_id;
|
|
|
|
} catch (e) {
|
|
|
|
// continue without accounts
|
|
|
|
}
|
|
|
|
}
|
2019-04-26 22:30:33 +02:00
|
|
|
const prefs = {};
|
|
|
|
if (config.survey_url) {
|
|
|
|
prefs.surveyUrl = config.survey_url;
|
|
|
|
}
|
2021-05-06 06:15:02 +02:00
|
|
|
const baseUrl = config.deriveBaseUrl(req);
|
2022-04-12 15:58:58 +02:00
|
|
|
const uiAssets = {
|
|
|
|
android_chrome_192px: assets.get('android-chrome-192x192.png'),
|
|
|
|
android_chrome_512px: assets.get('android-chrome-512x512.png'),
|
|
|
|
apple_touch_icon: assets.get('apple-touch-icon.png'),
|
|
|
|
favicon_16px: assets.get('favicon-16x16.png'),
|
|
|
|
favicon_32px: assets.get('favicon-32x32.png'),
|
|
|
|
icon: assets.get('icon.svg'),
|
|
|
|
safari_pinned_tab: assets.get('safari-pinned-tab.svg'),
|
|
|
|
facebook: baseUrl + '/' + assets.get('send-fb.jpg'),
|
|
|
|
twitter: baseUrl + '/' + assets.get('send-twitter.jpg'),
|
2022-08-08 00:37:17 +02:00
|
|
|
wordmark: assets.get('wordmark.svg') + '#logo',
|
|
|
|
custom_css: assets.get('undefined')
|
2022-04-12 15:58:58 +02:00
|
|
|
};
|
|
|
|
Object.keys(uiAssets).forEach(index => {
|
|
|
|
if (config.ui_custom_assets[index] !== '')
|
|
|
|
uiAssets[index] = config.ui_custom_assets[index];
|
|
|
|
});
|
2017-08-24 23:54:02 +02:00
|
|
|
return {
|
2018-12-21 19:27:46 +01:00
|
|
|
archive: {
|
|
|
|
numFiles: 0
|
|
|
|
},
|
2017-08-24 23:54:02 +02:00
|
|
|
locale,
|
2018-09-19 18:01:19 +02:00
|
|
|
capabilities: { account: false },
|
2018-11-20 15:50:59 +01:00
|
|
|
translate: getTranslator(locale),
|
2022-08-08 00:37:17 +02:00
|
|
|
title: config.custom_title,
|
|
|
|
description: config.custom_description,
|
2021-05-06 06:15:02 +02:00
|
|
|
baseUrl,
|
2022-04-12 15:58:58 +02:00
|
|
|
ui: {
|
|
|
|
colors: {
|
|
|
|
primary: config.ui_color_primary,
|
|
|
|
accent: config.ui_color_accent
|
|
|
|
},
|
|
|
|
assets: uiAssets
|
|
|
|
},
|
2017-08-24 23:54:02 +02:00
|
|
|
storage: {
|
|
|
|
files: []
|
|
|
|
},
|
2017-09-14 21:15:08 +02:00
|
|
|
fileInfo: {},
|
2018-08-08 00:40:17 +02:00
|
|
|
cspNonce: req.cspNonce,
|
2018-09-14 17:00:33 +02:00
|
|
|
user: { avatar: assets.get('user.svg'), loggedIn: false },
|
2019-03-14 21:17:47 +01:00
|
|
|
robots,
|
2018-11-20 21:07:47 +01:00
|
|
|
authConfig,
|
2019-04-26 22:30:33 +02:00
|
|
|
prefs,
|
2017-08-24 23:54:02 +02:00
|
|
|
layout
|
|
|
|
};
|
|
|
|
};
|