import 'reflect-metadata';
import { Ignitor, prettyPrintError } from '@adonisjs/core';
import { execSync } from 'child_process';

const APP_ROOT = new URL('../', import.meta.url);
const IMPORTER = (filePath) => {
    if (filePath.startsWith('./') || filePath.startsWith('../')) {
        return import(new URL(filePath, APP_ROOT).href);
    }
    return import(filePath);
};

// Auto-run migrations on startup
try {
    console.log('[Migration] Running database migrations...');
    execSync('node ace migration:run --force', {
        cwd: new URL('../', import.meta.url).pathname,
        stdio: 'inherit'
    });
    console.log('[Migration] Migrations completed successfully.');
} catch (err) {
    console.error('[Migration] Migration failed:', err.message);
}



new Ignitor(APP_ROOT, { importer: IMPORTER })
    .tap((app) => {
    app.booting(async () => {
        await import('#start/env');
    });
    app.listen('SIGTERM', () => app.terminate());
    app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate());
})
    .httpServer()
    .start()
    .catch((error) => {
    process.exitCode = 1;
    prettyPrintError(error);
});
//# sourceMappingURL=server.js.map
