added /config endpoint, use fewer globals (#1172)
* added /config endpoint, use fewer globals * fixed integration tests
This commit is contained in:
parent
8df400a676
commit
1c44d1d0f9
15 changed files with 92 additions and 80 deletions
21
server/clientConstants.js
Normal file
21
server/clientConstants.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
const config = require('./config');
|
||||
|
||||
module.exports = {
|
||||
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
|
||||
},
|
||||
DEFAULTS: {
|
||||
DOWNLOAD_COUNTS: config.download_counts,
|
||||
EXPIRE_TIMES_SECONDS: config.expire_times_seconds,
|
||||
EXPIRE_SECONDS: config.default_expire_seconds
|
||||
}
|
||||
};
|
|
@ -1,6 +1,7 @@
|
|||
const html = require('choo/html');
|
||||
const raw = require('choo/html/raw');
|
||||
const config = require('./config');
|
||||
const clientConstants = require('./clientConstants');
|
||||
|
||||
let sentry = '';
|
||||
if (config.sentry_id) {
|
||||
|
@ -44,23 +45,8 @@ module.exports = function(state) {
|
|||
window.location.assign('/unsupported/outdated');
|
||||
}
|
||||
|
||||
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 = {
|
||||
DOWNLOAD_COUNTS: ${JSON.stringify(config.download_counts)},
|
||||
EXPIRE_TIMES_SECONDS: ${JSON.stringify(config.expire_times_seconds)},
|
||||
EXPIRE_SECONDS: ${config.default_expire_seconds}
|
||||
};
|
||||
var LIMITS = ${JSON.stringify(clientConstants.LIMITS)};
|
||||
var DEFAULTS = ${JSON.stringify(clientConstants.DEFAULTS)};
|
||||
const LOCALE = '${state.locale}';
|
||||
const downloadMetadata = ${
|
||||
state.downloadMetadata ? raw(JSON.stringify(state.downloadMetadata)) : '{}'
|
||||
|
|
|
@ -8,6 +8,7 @@ const auth = require('../middleware/auth');
|
|||
const language = require('../middleware/language');
|
||||
const pages = require('./pages');
|
||||
const filelist = require('./filelist');
|
||||
const clientConstants = require('../clientConstants');
|
||||
|
||||
const IS_DEV = config.env === 'development';
|
||||
const ID_REGEX = '([0-9a-fA-F]{10})';
|
||||
|
@ -70,6 +71,9 @@ module.exports = function(app) {
|
|||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.text());
|
||||
app.get('/', language, pages.index);
|
||||
app.get('/config', function(req, res) {
|
||||
res.json(clientConstants);
|
||||
});
|
||||
app.get('/error', language, pages.blank);
|
||||
app.get('/oauth', language, pages.blank);
|
||||
app.get('/legal', language, pages.legal);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue