mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-22 11:45:06 +02:00
add migration to set trust_proxy to 1 if it exists in config
This commit is contained in:
parent
97ae76e4e7
commit
58ba0d07b0
4 changed files with 97 additions and 1 deletions
46
server/setup/scriptsSqlite/1.6.0.ts
Normal file
46
server/setup/scriptsSqlite/1.6.0.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { configFilePath1, configFilePath2 } from "@server/lib/consts";
|
||||
import fs from "fs";
|
||||
import yaml from "js-yaml";
|
||||
|
||||
const version = "1.6.0";
|
||||
|
||||
export default async function migration() {
|
||||
console.log(`Running setup script ${version}...`);
|
||||
|
||||
try {
|
||||
// Determine which config file exists
|
||||
const filePaths = [configFilePath1, configFilePath2];
|
||||
let filePath = "";
|
||||
for (const path of filePaths) {
|
||||
if (fs.existsSync(path)) {
|
||||
filePath = path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!filePath) {
|
||||
throw new Error(
|
||||
`No config file found (expected config.yml or config.yaml).`
|
||||
);
|
||||
}
|
||||
|
||||
// Read and parse the YAML file
|
||||
let rawConfig: any;
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
rawConfig = yaml.load(fileContents);
|
||||
|
||||
if (rawConfig.server?.trust_proxy) {
|
||||
rawConfig.server.trust_proxy = 1;
|
||||
}
|
||||
|
||||
// Write the updated YAML back to the file
|
||||
const updatedYaml = yaml.dump(rawConfig);
|
||||
fs.writeFileSync(filePath, updatedYaml, "utf8");
|
||||
|
||||
console.log(`Set trust_proxy to 1 in config file`);
|
||||
} catch (e) {
|
||||
console.log(`Unable to migrate config file. Error: ${e}`);
|
||||
}
|
||||
|
||||
console.log(`${version} migration complete`);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue