2017-08-24 21:54:02 +00:00
|
|
|
const config = require('../config');
|
2018-09-14 15:00:33 +00:00
|
|
|
const { getFxaConfig } = require('../fxa');
|
2017-08-24 21:54:02 +00:00
|
|
|
|
|
|
|
let sentry = '';
|
|
|
|
if (config.sentry_id) {
|
|
|
|
//eslint-disable-next-line node/no-missing-require
|
|
|
|
const version = require('../../dist/version.json');
|
|
|
|
sentry = `
|
|
|
|
var RAVEN_CONFIG = {
|
|
|
|
release: '${version.version}',
|
|
|
|
tags: {
|
|
|
|
commit: '${version.commit}'
|
|
|
|
},
|
|
|
|
dataCallback: function (data) {
|
|
|
|
var hash = window.location.hash;
|
|
|
|
if (hash) {
|
|
|
|
return JSON.parse(JSON.stringify(data).replace(new RegExp(hash.slice(1), 'g'), ''));
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var SENTRY_ID = '${config.sentry_id}';
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
let ga = '';
|
|
|
|
if (config.analytics_id) {
|
2017-08-25 20:13:45 +00:00
|
|
|
ga = `var GOOGLE_ANALYTICS_ID = '${config.analytics_id}';`;
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
|
2018-09-14 15:00:33 +00:00
|
|
|
module.exports = async function(req, res) {
|
2018-09-19 19:53:23 +00:00
|
|
|
let authConfig = '';
|
|
|
|
if (config.fxa_client_id) {
|
|
|
|
const fxaConfig = await getFxaConfig();
|
|
|
|
fxaConfig.client_id = config.fxa_client_id;
|
|
|
|
authConfig = `var AUTH_CONFIG = ${JSON.stringify(fxaConfig)};`;
|
|
|
|
}
|
2018-09-14 15:00:33 +00:00
|
|
|
/* eslint-disable no-useless-escape */
|
|
|
|
const jsconfig = `
|
|
|
|
var isIE = /trident\\\/7\.|msie/i.test(navigator.userAgent);
|
|
|
|
var isUnsupportedPage = /\\\/unsupported/.test(location.pathname);
|
|
|
|
if (isIE && !isUnsupportedPage) {
|
|
|
|
window.location.replace('/unsupported/ie');
|
|
|
|
}
|
|
|
|
var LIMITS = {
|
|
|
|
ANON: {
|
|
|
|
MAX_FILE_SIZE: ${config.anon_max_file_size},
|
|
|
|
MAX_DOWNLOADS: ${config.anon_max_downloads},
|
|
|
|
MAX_EXPIRE_SECONDS: ${config.anon_max_expire_seconds},
|
|
|
|
},
|
|
|
|
MAX_FILE_SIZE: ${config.max_file_size},
|
|
|
|
MAX_DOWNLOADS: ${config.max_downloads},
|
|
|
|
MAX_EXPIRE_SECONDS: ${config.max_expire_seconds},
|
|
|
|
MAX_FILES_PER_ARCHIVE: ${config.max_files_per_archive},
|
|
|
|
MAX_ARCHIVES_PER_USER: ${config.max_archives_per_user}
|
|
|
|
};
|
|
|
|
var DEFAULTS = {
|
2018-09-24 22:08:39 +00:00
|
|
|
DOWNLOAD_COUNTS: ${JSON.stringify(config.download_counts)},
|
|
|
|
EXPIRE_TIMES_SECONDS: ${JSON.stringify(config.expire_times_seconds)},
|
2018-09-14 15:00:33 +00:00
|
|
|
EXPIRE_SECONDS: ${config.default_expire_seconds}
|
|
|
|
};
|
2018-09-19 19:53:23 +00:00
|
|
|
${authConfig};
|
2018-09-14 15:00:33 +00:00
|
|
|
${ga}
|
|
|
|
${sentry}
|
|
|
|
`;
|
2017-08-24 21:54:02 +00:00
|
|
|
res.set('Content-Type', 'application/javascript');
|
|
|
|
res.send(jsconfig);
|
|
|
|
};
|