diff --git a/controllers/albumsController.js b/controllers/albumsController.js index 235513f..c2c662a 100644 --- a/controllers/albumsController.js +++ b/controllers/albumsController.js @@ -22,7 +22,7 @@ const self = { onHold: new Set() } -const homeDomain = config.homeDomain || config.domain +const homeDomain = utils.conf.homeDomain || utils.conf.domain const zipMaxTotalSize = parseInt(config.cloudflare.zipMaxTotalSize) const zipMaxTotalSizeBytes = zipMaxTotalSize * 1e6 @@ -447,14 +447,14 @@ self.get = async (req, res, next) => { for (const file of files) { if (req._upstreamCompat) { - file.url = `${config.domain}/${file.name}` + file.url = `${utils.conf.domain}/${file.name}` } else { - file.file = `${config.domain}/${file.name}` + file.file = `${utils.conf.domain}/${file.name}` } const extname = utils.extname(file.name) if (utils.mayGenerateThumb(extname)) { - file.thumb = `${config.domain}/thumbs/${file.name.slice(0, -extname.length)}.png` + file.thumb = `${utils.conf.domain}/thumbs/${file.name.slice(0, -extname.length)}.png` if (req._upstreamCompat) file.thumbSquare = file.thumb } } diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 978b968..62fc4e2 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -938,7 +938,7 @@ self.sendUploadResponse = async (req, res, user, result) => { files: result.map(file => { const map = { name: file.name, - url: `${config.domain ? `${config.domain}/` : ''}${file.name}` + url: `${utils.conf.domain ? `${utils.conf.domain}/` : ''}${file.name}` } // If a temporary upload, add expiry date @@ -1021,7 +1021,7 @@ self.list = async (req, res, next) => { const ismoderator = perms.is(user, 'moderator') if (all && !ismoderator) return res.status(403).end() - const basedomain = config.domain + const basedomain = utils.conf.domain // Thresholds for regular users const MAX_WILDCARDS_IN_KEY = 2 diff --git a/controllers/utilsController.js b/controllers/utilsController.js index 43cdeab..a770d1e 100644 --- a/controllers/utilsController.js +++ b/controllers/utilsController.js @@ -16,6 +16,12 @@ const logger = require('./../logger') const self = { db: knex(config.database), + conf: { + // Allow some config options to be overriden via env vars + port: process.env.PORT || config.port, + domain: process.env.DOMAIN || config.domain, + homeDomain: process.env.HOME_DOMAIN || config.homeDomain + }, scan: { instance: null, version: null, @@ -632,8 +638,8 @@ self.purgeCloudflareCache = async (names, uploads, thumbs) => { return [{ success: false, files: [], errors }] } - let domain = config.domain - if (!uploads) domain = config.homeDomain + let domain = self.conf.domain + if (!uploads) domain = self.conf.homeDomain const thumbNames = [] names = names.map(name => { diff --git a/lolisafe.js b/lolisafe.js index b05aabd..f92b9ca 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -343,8 +343,8 @@ safe.use('/api', api) } // Binds Express to port - await new Promise(resolve => safe.listen(config.port, () => resolve())) - logger.log(`lolisafe started on port ${config.port}`) + await new Promise(resolve => safe.listen(utils.conf.port, () => resolve())) + logger.log(`lolisafe started on port ${utils.conf.port}`) // Cache control (safe.fiery.me) // Purge Cloudflare cache