refactor(sql): full changes to localhost if on produciton server
This commit is contained in:
@@ -4,48 +4,47 @@ import { createLog } from "../../logger/logger.js";
|
|||||||
import { serverSettings } from "../../server/controller/settings/getSettings.js";
|
import { serverSettings } from "../../server/controller/settings/getSettings.js";
|
||||||
|
|
||||||
export const prodSqlConfig = async () => {
|
export const prodSqlConfig = async () => {
|
||||||
try {
|
try {
|
||||||
//const serverSetting = await db.select().from(settings);
|
//const serverSetting = await db.select().from(settings);
|
||||||
const serverSetting = serverSettings as any;
|
const serverSetting = serverSettings as any;
|
||||||
// create dummy type data
|
// create dummy type data
|
||||||
const server = serverSetting.filter((s: any) => s.name === "dbServer");
|
const server = serverSetting.filter((s: any) => s.name === "dbServer");
|
||||||
const plantToken = serverSetting.filter(
|
const plantToken = serverSetting.filter(
|
||||||
(s: any) => s.name === "plantToken"
|
(s: any) => s.name === "plantToken",
|
||||||
);
|
);
|
||||||
const dbUser = serverSetting.filter((s: any) => s.name === "dbUser");
|
const dbUser = serverSetting.filter((s: any) => s.name === "dbUser");
|
||||||
// if erroring out double check the password was actually encoded before saving
|
// if erroring out double check the password was actually encoded before saving
|
||||||
const dbPassword = serverSetting.filter(
|
const dbPassword = serverSetting.filter((s: any) => s.name === "dbPass");
|
||||||
(s: any) => s.name === "dbPass"
|
|
||||||
);
|
|
||||||
|
|
||||||
const sqlConfig = {
|
const sqlConfig = {
|
||||||
server: server[0].value,
|
server:
|
||||||
database: `AlplaPROD_${plantToken[0].value}_cus`,
|
process.env.NODE_ENV !== "development" ? "localhost" : server[0].value,
|
||||||
user: dbUser[0].value,
|
database: `AlplaPROD_${plantToken[0].value}_cus`,
|
||||||
password: atob(dbPassword[0].value),
|
user: dbUser[0].value,
|
||||||
options: {
|
password: atob(dbPassword[0].value),
|
||||||
encrypt: true,
|
options: {
|
||||||
trustServerCertificate: true,
|
encrypt: true,
|
||||||
},
|
trustServerCertificate: true,
|
||||||
requestTimeout: 90000, // in milliseconds
|
},
|
||||||
pool: {
|
requestTimeout: 90000, // in milliseconds
|
||||||
max: 20, // Maximum number of connections in the pool
|
pool: {
|
||||||
min: 0, // Minimum number of connections in the pool
|
max: 20, // Maximum number of connections in the pool
|
||||||
idleTimeoutMillis: 10000, // How long a connection is allowed to be idle before being released
|
min: 0, // Minimum number of connections in the pool
|
||||||
reapIntervalMillis: 1000, // how often to check for idle resourses to destory
|
idleTimeoutMillis: 10000, // How long a connection is allowed to be idle before being released
|
||||||
acquireTimeoutMillis: 100000, // How long until a complete timeout happens
|
reapIntervalMillis: 1000, // how often to check for idle resourses to destory
|
||||||
},
|
acquireTimeoutMillis: 100000, // How long until a complete timeout happens
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
return sqlConfig;
|
return sqlConfig;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createLog(
|
createLog(
|
||||||
"info",
|
"info",
|
||||||
"lst",
|
"lst",
|
||||||
"sqlProd",
|
"sqlProd",
|
||||||
`${JSON.stringify(
|
`${JSON.stringify(
|
||||||
error
|
error,
|
||||||
)} "There was an error getting/setting up the config for the prod sql server."`
|
)} "There was an error getting/setting up the config for the prod sql server."`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user