state.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const config = require('./config');
  2. const layout = require('./layout');
  3. const assets = require('../common/assets');
  4. const getTranslator = require('./locale');
  5. const { getFxaConfig } = require('./fxa');
  6. module.exports = async function(req) {
  7. const locale = req.language || 'en-US';
  8. let authConfig = null;
  9. let robots = 'none';
  10. if (req.route && req.route.path === '/') {
  11. robots = 'all';
  12. }
  13. if (config.fxa_client_id) {
  14. try {
  15. authConfig = await getFxaConfig();
  16. authConfig.client_id = config.fxa_client_id;
  17. } catch (e) {
  18. // continue without accounts
  19. }
  20. }
  21. const prefs = {};
  22. if (config.survey_url) {
  23. prefs.surveyUrl = config.survey_url;
  24. }
  25. return {
  26. archive: {
  27. numFiles: 0
  28. },
  29. locale,
  30. capabilities: { account: false },
  31. translate: getTranslator(locale),
  32. title: 'Firefox Send',
  33. description:
  34. 'Encrypt and send files with a link that automatically expires to ensure your important documents don’t stay online forever.',
  35. baseUrl: config.base_url,
  36. ui: {},
  37. storage: {
  38. files: []
  39. },
  40. fileInfo: {},
  41. cspNonce: req.cspNonce,
  42. user: { avatar: assets.get('user.svg'), loggedIn: false },
  43. robots,
  44. authConfig,
  45. prefs,
  46. layout
  47. };
  48. };