Files
lstV2/server/globalUtils/createUrl.ts

33 lines
1.3 KiB
TypeScript

import {eq} from "drizzle-orm";
import {db} from "../../database/dbclient.js";
import {settings} from "../../database/schema/settings.js";
// create the test server stuff
const testServers = [
{token: "test1", port: 8940},
{token: "test2", port: 8941},
{token: "test3", port: 8942},
];
export const prodEndpointCreation = async (endpoint: string) => {
let url = "";
//get the plant token
const plantToken = await db.select().from(settings).where(eq(settings.name, "plantToken"));
// check if we are a test server
const testServer = testServers.some((server) => server.token === plantToken[0].value);
const server = await db.select().from(settings).where(eq(settings.name, "dbServer"));
if (testServer) {
//filter out what testserver we are
const test = testServers.filter((t) => t.token === plantToken[0].value);
// "https://usmcd1vms036.alpla.net:8942/application/public/v1.0/DemandManagement/ORDERS"
// "https://usmcd1vms036.alpla.net:8492/application/public/v1.0/DemandManagement/ORDERS"
url = `https://${server[0].value}.alpla.net:${test[0].port}/application${endpoint}`;
return url;
} else {
url = `https://${plantToken[0].value}prod.alpla.net/application${endpoint}`;
return url;
}
};