feat: always use DB_* and API_PATH_PREFIX env vars if set

This commit is contained in:
Dragory 2024-04-07 09:10:02 +00:00
parent e146ed6416
commit ae03c9e03b
No known key found for this signature in database
2 changed files with 6 additions and 21 deletions

View file

@ -10,7 +10,7 @@ import { initGuildsAPI } from "./guilds/index";
import { clientError, error, notFound } from "./responses";
import { startBackgroundTasks } from "./tasks";
const apiPathPrefix = env.NODE_ENV === "production" ? env.API_PATH_PREFIX ?? "" : "/api";
const apiPathPrefix = env.API_PATH_PREFIX || (env.NODE_ENV === "development" ? "/api" : "");
const app = express();

View file

@ -1,7 +1,6 @@
import moment from "moment-timezone";
import path from "path";
import { DataSource } from "typeorm";
import { MysqlConnectionOptions } from "typeorm/driver/mysql/MysqlConnectionOptions.js";
import { env } from "../env";
import { backendDir } from "../paths";
@ -10,27 +9,13 @@ moment.tz.setDefault("UTC");
const entities = path.relative(process.cwd(), path.resolve(backendDir, "dist/data/entities/*.js"));
const migrations = path.relative(process.cwd(), path.resolve(backendDir, "dist/migrations/*.js"));
type DbOpts = Pick<MysqlConnectionOptions, "host" | "port" | "username" | "password" | "database">;
const dbOpts: DbOpts =
env.NODE_ENV === "production"
? {
host: env.DB_HOST,
port: env.DB_PORT,
username: env.DB_USER,
password: env.DB_PASSWORD,
database: env.DB_DATABASE,
}
: {
host: "mysql",
port: 3306,
username: "zeppelin",
password: env.DEVELOPMENT_MYSQL_PASSWORD,
database: "zeppelin",
};
export const dataSource = new DataSource({
type: "mysql",
...dbOpts,
host: env.DB_HOST || "mysql",
port: env.DB_PORT || 3306,
username: env.DB_USER || "zeppelin",
password: env.DB_PASSWORD || env.DEVELOPMENT_MYSQL_PASSWORD,
database: env.DB_DATABASE || "zeppelin",
charset: "utf8mb4",
supportBigNumbers: true,
bigNumberStrings: true,