Skip to content

Node.js based forum software built for the modern web

676 B
Raw Blame
'use strict';

const fs = require('fs');
const path = require('path');
const nconf = require('nconf');

module.exports = {
	name: 'Backfill trust_proxy for upgraded installs',
	timestamp: Date.UTC(2026, 6, 28),
	method: async function () {
		const pathToConfig = path.resolve(__dirname, '../../../', nconf.get('config') || 'config.json');

		let configJSON;
		try {
			configJSON = JSON.parse(await fs.promises.readFile(pathToConfig, 'utf8')) || {};
		} catch (err) {
			configJSON = {};
		}

		if (!Object.hasOwn(configJSON, 'trust_proxy')) {
			await fs.promises.writeFile(pathToConfig, JSON.stringify({
				...configJSON,
				trust_proxy: true,
			}, null, 4));
		}
	},
};