1.0.0-beta10.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { configFilePath1, configFilePath2 } from "@server/lib/consts";
  2. import fs from "fs";
  3. import yaml from "js-yaml";
  4. export default async function migration() {
  5. console.log("Running setup script 1.0.0-beta.9...");
  6. try {
  7. // Determine which config file exists
  8. const filePaths = [configFilePath1, configFilePath2];
  9. let filePath = "";
  10. for (const path of filePaths) {
  11. if (fs.existsSync(path)) {
  12. filePath = path;
  13. break;
  14. }
  15. }
  16. if (!filePath) {
  17. throw new Error(
  18. `No config file found (expected config.yml or config.yaml).`
  19. );
  20. }
  21. // Read and parse the YAML file
  22. let rawConfig: any;
  23. const fileContents = fs.readFileSync(filePath, "utf8");
  24. rawConfig = yaml.load(fileContents);
  25. rawConfig.server.secure_cookies = true;
  26. // Write the updated YAML back to the file
  27. const updatedYaml = yaml.dump(rawConfig);
  28. fs.writeFileSync(filePath, updatedYaml, "utf8");
  29. } catch (e) {
  30. console.log(
  31. `Failed to set secure_cookies to true in config. Please set it manually. https://docs.fossorial.io/Pangolin/Configuration/config`
  32. );
  33. return;
  34. }
  35. console.log("Done.");
  36. }