mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-05-07 15:23:06 -04:00
feat: parameterize PORT and MIGRATIONS_PATH environment variables (#253)
* feat: parameterize PORT and MIGRATIONS_PATH environment variables Allow configuring the server port (default: 4096) and migrations folder path via environment variables for flexible deployment. * fix: address PR review feedback - Use consistent schema syntax (string? instead of key?) - Remove config tests per maintainer request
This commit is contained in:
@@ -6,12 +6,16 @@ const envSchema = type({
|
||||
SERVER_IP: 'string = "localhost"',
|
||||
SERVER_IDLE_TIMEOUT: 'string.integer.parse = "60"',
|
||||
RESTIC_HOSTNAME: "string = 'zerobyte'",
|
||||
PORT: 'string.integer.parse = "4096"',
|
||||
MIGRATIONS_PATH: "string?",
|
||||
}).pipe((s) => ({
|
||||
__prod__: s.NODE_ENV === "production",
|
||||
environment: s.NODE_ENV,
|
||||
serverIp: s.SERVER_IP,
|
||||
serverIdleTimeout: s.SERVER_IDLE_TIMEOUT,
|
||||
resticHostname: s.RESTIC_HOSTNAME,
|
||||
port: s.PORT,
|
||||
migrationsPath: s.MIGRATIONS_PATH,
|
||||
}));
|
||||
|
||||
const parseConfig = (env: unknown) => {
|
||||
|
||||
@@ -14,9 +14,13 @@ const sqlite = new Database(DATABASE_URL);
|
||||
export const db = drizzle({ client: sqlite, schema });
|
||||
|
||||
export const runDbMigrations = () => {
|
||||
let migrationsFolder = path.join("/app", "assets", "migrations");
|
||||
let migrationsFolder: string;
|
||||
|
||||
if (!config.__prod__) {
|
||||
if (config.migrationsPath) {
|
||||
migrationsFolder = config.migrationsPath;
|
||||
} else if (config.__prod__) {
|
||||
migrationsFolder = path.join("/app", "assets", "migrations");
|
||||
} else {
|
||||
migrationsFolder = path.join("/app", "app", "drizzle");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ await validateRequiredMigrations(REQUIRED_MIGRATIONS);
|
||||
|
||||
startup();
|
||||
|
||||
logger.info(`Server is running at http://localhost:4096`);
|
||||
logger.info(`Server is running at http://localhost:${config.port}`);
|
||||
|
||||
export type AppType = typeof app;
|
||||
|
||||
@@ -36,7 +36,7 @@ process.on("SIGINT", async () => {
|
||||
|
||||
export default await createHonoServer({
|
||||
app,
|
||||
port: 4096,
|
||||
port: config.port,
|
||||
customBunServer: {
|
||||
idleTimeout: config.serverIdleTimeout,
|
||||
error(err) {
|
||||
|
||||
Reference in New Issue
Block a user