From 39a24c951c0c20aadc33554abef553307bb30449 Mon Sep 17 00:00:00 2001 From: Owen Schwartz Date: Sun, 22 Dec 2024 12:23:19 -0500 Subject: [PATCH] Copy in org domain from config for now --- server/index.ts | 2 ++ server/setup/copyInConfig.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 server/setup/copyInConfig.ts diff --git a/server/index.ts b/server/index.ts index 0e11a3a..389ca6d 100644 --- a/server/index.ts +++ b/server/index.ts @@ -3,9 +3,11 @@ import { createApiServer } from "./apiServer"; import { createNextServer } from "./nextServer"; import { createInternalServer } from "./internalServer"; import { User, UserOrg } from "./db/schema"; +import { copyInConfig } from "./setup/copyInConfig"; async function startServers() { await ensureActions(); + await copyInConfig(); // Start all servers const apiServer = createApiServer(); diff --git a/server/setup/copyInConfig.ts b/server/setup/copyInConfig.ts new file mode 100644 index 0000000..264bdcc --- /dev/null +++ b/server/setup/copyInConfig.ts @@ -0,0 +1,15 @@ +import { db } from "@server/db"; +import { orgs } from "../db/schema"; +import config from "@server/config"; +import { ne } from "drizzle-orm"; +import logger from "@server/logger"; + +export async function copyInConfig() { + // create a url from config.app.base_url and get the hostname + const domain = new URL(config.app.base_url).hostname; + + // update the domain on all of the orgs where the domain is not equal to the new domain + // TODO: eventually each org could have a unique domain that we do not want to overwrite, so this will be unnecessary + await db.update(orgs).set({ domain }).where(ne(orgs.domain, domain)); + logger.info("Updated orgs with new domain"); +} \ No newline at end of file