mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-04 10:05:53 +02:00
split base_url into dashboard_url and base_domain
This commit is contained in:
parent
26a165ab71
commit
e1f0834af4
17 changed files with 100 additions and 37 deletions
|
@ -5,7 +5,6 @@ import { eq, ne } from "drizzle-orm";
|
|||
import logger from "@server/logger";
|
||||
|
||||
export async function copyInConfig() {
|
||||
// create a url from config.getRawConfig().app.base_url and get the hostname
|
||||
const domain = config.getBaseDomain();
|
||||
const endpoint = config.getRawConfig().gerbil.base_endpoint;
|
||||
|
||||
|
|
|
@ -7,13 +7,15 @@ import { desc } from "drizzle-orm";
|
|||
import { __DIRNAME } from "@server/lib/consts";
|
||||
import { loadAppVersion } from "@server/lib/loadAppVersion";
|
||||
import m1 from "./scripts/1.0.0-beta1";
|
||||
import m2 from "./scripts/1.0.0-beta2";
|
||||
|
||||
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
|
||||
// EXCEPT FOR THE DATABASE AND THE SCHEMA
|
||||
|
||||
// Define the migration list with versions and their corresponding functions
|
||||
const migrations = [
|
||||
{ version: "1.0.0-beta.1", run: m1 }
|
||||
{ version: "1.0.0-beta.1", run: m1 },
|
||||
{ version: "1.0.0-beta.2", run: m2 }
|
||||
// Add new migrations here as they are created
|
||||
] as const;
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import logger from "@server/logger";
|
||||
|
||||
export default async function migration() {
|
||||
console.log("Running setup script 1.0.0-beta.1");
|
||||
console.log("Running setup script 1.0.0-beta.1...");
|
||||
// SQL operations would go here in ts format
|
||||
console.log("Done...");
|
||||
console.log("Done.");
|
||||
}
|
||||
|
|
59
server/setup/scripts/1.0.0-beta2.ts
Normal file
59
server/setup/scripts/1.0.0-beta2.ts
Normal file
|
@ -0,0 +1,59 @@
|
|||
import { configFilePath1, configFilePath2 } from "@server/lib/consts";
|
||||
import fs from "fs";
|
||||
import yaml from "js-yaml";
|
||||
|
||||
export default async function migration() {
|
||||
console.log("Running setup script 1.0.0-beta.2...");
|
||||
|
||||
// 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);
|
||||
|
||||
// Validate the structure
|
||||
if (!rawConfig.app || !rawConfig.app.base_url) {
|
||||
throw new Error(`Invalid config file: app.base_url is missing.`);
|
||||
}
|
||||
|
||||
// Move base_url to dashboard_url and calculate base_domain
|
||||
const baseUrl = rawConfig.app.base_url;
|
||||
rawConfig.app.dashboard_url = baseUrl;
|
||||
rawConfig.app.base_domain = getBaseDomain(baseUrl);
|
||||
|
||||
// Remove the old base_url
|
||||
delete rawConfig.app.base_url;
|
||||
|
||||
// Write the updated YAML back to the file
|
||||
const updatedYaml = yaml.dump(rawConfig);
|
||||
fs.writeFileSync(filePath, updatedYaml, "utf8");
|
||||
|
||||
console.log("Done.");
|
||||
}
|
||||
|
||||
function getBaseDomain(url: string): string {
|
||||
const newUrl = new URL(url);
|
||||
const hostname = newUrl.hostname;
|
||||
const parts = hostname.split(".");
|
||||
|
||||
if (parts.length <= 2) {
|
||||
return parts.join(".");
|
||||
}
|
||||
|
||||
return parts.slice(-2).join(".");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue