jsconfig.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const config = require('../config');
  2. const { getFxaConfig } = require('../fxa');
  3. let sentry = '';
  4. if (config.sentry_id) {
  5. //eslint-disable-next-line node/no-missing-require
  6. const version = require('../../dist/version.json');
  7. sentry = `
  8. var RAVEN_CONFIG = {
  9. release: '${version.version}',
  10. tags: {
  11. commit: '${version.commit}'
  12. },
  13. dataCallback: function (data) {
  14. var hash = window.location.hash;
  15. if (hash) {
  16. return JSON.parse(JSON.stringify(data).replace(new RegExp(hash.slice(1), 'g'), ''));
  17. }
  18. return data;
  19. }
  20. }
  21. var SENTRY_ID = '${config.sentry_id}';
  22. `;
  23. }
  24. let ga = '';
  25. if (config.analytics_id) {
  26. ga = `var GOOGLE_ANALYTICS_ID = '${config.analytics_id}';`;
  27. }
  28. module.exports = async function(req, res) {
  29. let authConfig = '';
  30. if (config.fxa_client_id) {
  31. const fxaConfig = await getFxaConfig();
  32. fxaConfig.client_id = config.fxa_client_id;
  33. authConfig = `var AUTH_CONFIG = ${JSON.stringify(fxaConfig)};`;
  34. }
  35. /* eslint-disable no-useless-escape */
  36. const jsconfig = `
  37. var isIE = /trident\\\/7\.|msie/i.test(navigator.userAgent);
  38. var isUnsupportedPage = /\\\/unsupported/.test(location.pathname);
  39. if (isIE && !isUnsupportedPage) {
  40. window.location.replace('/unsupported/ie');
  41. }
  42. var LIMITS = {
  43. ANON: {
  44. MAX_FILE_SIZE: ${config.anon_max_file_size},
  45. MAX_DOWNLOADS: ${config.anon_max_downloads},
  46. MAX_EXPIRE_SECONDS: ${config.anon_max_expire_seconds},
  47. },
  48. MAX_FILE_SIZE: ${config.max_file_size},
  49. MAX_DOWNLOADS: ${config.max_downloads},
  50. MAX_EXPIRE_SECONDS: ${config.max_expire_seconds},
  51. MAX_FILES_PER_ARCHIVE: ${config.max_files_per_archive},
  52. MAX_ARCHIVES_PER_USER: ${config.max_archives_per_user}
  53. };
  54. var DEFAULTS = {
  55. DOWNLOAD_COUNTS: ${JSON.stringify(config.download_counts)},
  56. EXPIRE_TIMES_SECONDS: ${JSON.stringify(config.expire_times_seconds)},
  57. EXPIRE_SECONDS: ${config.default_expire_seconds}
  58. };
  59. ${authConfig};
  60. ${ga}
  61. ${sentry}
  62. `;
  63. res.set('Content-Type', 'application/javascript');
  64. res.send(jsconfig);
  65. };