fix: skip database connection during build when MONGO_URL is not set
All checks were successful
CI / build-and-deploy (push) Successful in 1m23s
All checks were successful
CI / build-and-deploy (push) Successful in 1m23s
Add check for MONGO_URL existence before attempting database connection in hooks.server.ts. This prevents build failures in CI environments where no .env file is present, while still initializing the connection properly at runtime on the server.
This commit is contained in:
@@ -7,20 +7,25 @@ import { sequence } from "@sveltejs/kit/hooks"
|
||||
import * as auth from "./auth"
|
||||
import { initializeScheduler } from "./lib/server/scheduler"
|
||||
import { dbConnect } from "./utils/db"
|
||||
import { env } from "$env/dynamic/private"
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
// Initialize database connection on server startup
|
||||
console.log('🚀 Server starting - initializing database connection...');
|
||||
await dbConnect().then(() => {
|
||||
console.log('✅ Database connected successfully');
|
||||
// Initialize the recurring payment scheduler after DB is ready
|
||||
initializeScheduler();
|
||||
console.log('✅ Recurring payment scheduler initialized');
|
||||
}).catch((error) => {
|
||||
console.error('❌ Failed to connect to database on startup:', error);
|
||||
// Don't crash the server - API routes will attempt reconnection
|
||||
});
|
||||
// Initialize database connection on server startup (skip during build when no env vars)
|
||||
if (env.MONGO_URL) {
|
||||
console.log('🚀 Server starting - initializing database connection...');
|
||||
await dbConnect().then(() => {
|
||||
console.log('✅ Database connected successfully');
|
||||
// Initialize the recurring payment scheduler after DB is ready
|
||||
initializeScheduler();
|
||||
console.log('✅ Recurring payment scheduler initialized');
|
||||
}).catch((error) => {
|
||||
console.error('❌ Failed to connect to database on startup:', error);
|
||||
// Don't crash the server - API routes will attempt reconnection
|
||||
});
|
||||
} else {
|
||||
console.log('⚠️ MONGO_URL not set - skipping database initialization (build mode)');
|
||||
}
|
||||
|
||||
async function authorization({ event, resolve }) {
|
||||
const session = await event.locals.auth();
|
||||
|
||||
Reference in New Issue
Block a user