mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-18 04:37:19 +02:00
Resolve production errors and improve system stability and reliability
Fix critical production errors, including Bad Gateway issues and TypeScript compilation failures, by implementing comprehensive route registration, correcting service configurations, and ensuring production build success. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7c468936-2a88-4686-ac0a-84921a45222d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/7c468936-2a88-4686-ac0a-84921a45222d/cH9Kvea
This commit is contained in:
1 parent
d128c721e8
commit
1745e73b52
5 files changed
+34
-99
No files matched your search
+16
-81
@@ -37,9 +37,17 @@ app.use((req, res, next) => {
|
||||
next();
|
||||
});
|
||||
|
||||
// Simple production routes
|
||||
// Import all routes for production
|
||||
import { registerRoutes } from "./routes.js";
|
||||
|
||||
async function registerProductionRoutes(app: Express): Promise<Server> {
|
||||
// Health check endpoint
|
||||
console.log('🔧 Registering all production routes...');
|
||||
|
||||
// Register ALL API routes (same as development)
|
||||
const server = await registerRoutes(app);
|
||||
console.log('✅ All routes registered successfully for production');
|
||||
|
||||
// Additional health check endpoint for production monitoring
|
||||
app.get('/api/health', (req: Request, res: Response) => {
|
||||
res.status(200).json({
|
||||
status: 'healthy',
|
||||
@@ -51,12 +59,12 @@ async function registerProductionRoutes(app: Express): Promise<Server> {
|
||||
});
|
||||
});
|
||||
|
||||
// Emergency admin reset endpoint (production only)
|
||||
// Emergency admin reset endpoint (production only)
|
||||
app.post('/api/emergency-admin-reset', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const { secret } = req.body;
|
||||
|
||||
// Require emergency secret (can be set via environment variable)
|
||||
// Require emergency secret
|
||||
const emergencySecret = process.env.EMERGENCY_SECRET || 'logiflow-admin-reset-2025';
|
||||
if (secret !== emergencySecret) {
|
||||
return res.status(403).json({ error: 'Invalid emergency secret' });
|
||||
@@ -64,17 +72,12 @@ async function registerProductionRoutes(app: Express): Promise<Server> {
|
||||
|
||||
console.log('🚨 EMERGENCY: Admin password reset requested');
|
||||
|
||||
// Find existing admin
|
||||
// Find and reset admin
|
||||
const existingAdmin = await storage.getUserByUsername('admin');
|
||||
if (existingAdmin) {
|
||||
// Generate new password hash
|
||||
const crypto = await import('crypto');
|
||||
const scrypt = await import('util').then(util => util.promisify(crypto.scrypt));
|
||||
const salt = crypto.randomBytes(16).toString("hex");
|
||||
const buf = (await scrypt('admin', salt, 64)) as Buffer;
|
||||
const newPassword = `${buf.toString("hex")}.${salt}`;
|
||||
const { hashPasswordSimple } = await import('./localAuth.production.js');
|
||||
const newPassword = await hashPasswordSimple('admin');
|
||||
|
||||
// Update admin password
|
||||
await storage.updateUser(existingAdmin.id, {
|
||||
password: newPassword,
|
||||
passwordChanged: false
|
||||
@@ -95,75 +98,7 @@ async function registerProductionRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
// Setup authentication
|
||||
setupLocalAuth(app);
|
||||
|
||||
// Import and register all routes from routes.ts instead of having limited routes
|
||||
const { registerRoutes } = await import('./routes.js');
|
||||
await registerRoutes(app);
|
||||
|
||||
// Additional health check route for Docker compatibility
|
||||
app.get('/api/groups', requireAuth, async (req: Request, res: Response) => {
|
||||
try {
|
||||
const groups = await storage.getGroups();
|
||||
res.json(groups);
|
||||
} catch (error) {
|
||||
console.error('Error fetching groups:', error);
|
||||
res.status(500).json({ error: 'Failed to fetch groups' });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/suppliers', requireAuth, async (req: Request, res: Response) => {
|
||||
try {
|
||||
const suppliers = await storage.getSuppliers();
|
||||
res.json(suppliers);
|
||||
} catch (error) {
|
||||
console.error('Error fetching suppliers:', error);
|
||||
res.status(500).json({ error: 'Failed to fetch suppliers' });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/orders', requireAuth, async (req: Request, res: Response) => {
|
||||
try {
|
||||
const orders = await storage.getOrders();
|
||||
res.json(orders);
|
||||
} catch (error) {
|
||||
console.error('Error fetching orders:', error);
|
||||
res.status(500).json({ error: 'Failed to fetch orders' });
|
||||
}
|
||||
});
|
||||
|
||||
// Weather API for compatibility
|
||||
app.get('/api/weather', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const weatherData = {
|
||||
today: {
|
||||
date: '2025-08-11',
|
||||
location: 'Nancy, France',
|
||||
tempMax: '30.9',
|
||||
tempMin: '13.9',
|
||||
icon: 'clear-day',
|
||||
conditions: 'Clear',
|
||||
isCurrentYear: true
|
||||
},
|
||||
previousYear: {
|
||||
date: '2024-08-11',
|
||||
location: 'Nancy, France',
|
||||
tempMax: '30.9',
|
||||
tempMin: '15.8',
|
||||
icon: 'clear-day',
|
||||
conditions: 'Clear',
|
||||
isCurrentYear: false
|
||||
},
|
||||
lastFetch: new Date().toISOString()
|
||||
};
|
||||
|
||||
res.json(weatherData);
|
||||
} catch (error: any) {
|
||||
console.error('Weather API error:', error);
|
||||
res.status(500).json({ error: 'Failed to fetch weather data' });
|
||||
}
|
||||
});
|
||||
// Pas besoin de setupLocalAuth ici car registerRoutes le fait déjà
|
||||
|
||||
const server = createServer(app);
|
||||
return server;
|
||||
|
||||
+3
-3
@@ -259,7 +259,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
console.log('✅ Supplier creation successful:', { id: supplier.id, name: supplier.name });
|
||||
|
||||
res.json(supplier);
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('❌ Failed to create supplier:', {
|
||||
error: (error as Error).message,
|
||||
stack: error.stack,
|
||||
@@ -442,7 +442,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
});
|
||||
|
||||
res.json(order);
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error("❌ Error creating order:", {
|
||||
error: (error as Error).message,
|
||||
stack: error.stack,
|
||||
@@ -752,7 +752,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
// Auto-valider le rapprochement
|
||||
await storage.updateDelivery(id, {
|
||||
reconciled: true,
|
||||
validatedAt: new Date().toISOString()
|
||||
validatedAt: new Date()
|
||||
});
|
||||
|
||||
console.log(`✅ Auto-reconciliation: Delivery #${id} automatically validated for supplier ${supplier.name}`);
|
||||
|
||||
+6
-6
@@ -1687,7 +1687,7 @@ export class MemStorage implements IStorage {
|
||||
status: 'En attente de Commande',
|
||||
isPromotionalPrice: false,
|
||||
customerNotified: false,
|
||||
notes: 'Livraison urgente demandée',
|
||||
notes: 'Livraison urgente demandée' as string | null,
|
||||
createdAt: new Date('2025-01-15'),
|
||||
updatedAt: new Date('2025-01-15'),
|
||||
};
|
||||
@@ -1709,7 +1709,7 @@ export class MemStorage implements IStorage {
|
||||
status: 'Commande passée',
|
||||
isPromotionalPrice: true,
|
||||
customerNotified: true,
|
||||
notes: null,
|
||||
notes: null as string | null,
|
||||
createdAt: new Date('2025-01-10'),
|
||||
updatedAt: new Date('2025-01-12'),
|
||||
};
|
||||
@@ -1731,10 +1731,10 @@ export class MemStorage implements IStorage {
|
||||
status: 'en_cours',
|
||||
quantity: 24,
|
||||
unit: 'pièces',
|
||||
notes: 'À vendre rapidement',
|
||||
notes: 'À vendre rapidement' as string | null,
|
||||
location: 'Frigo principal',
|
||||
alertThreshold: 5,
|
||||
validatedBy: null,
|
||||
validatedBy: null as string | null,
|
||||
validatedAt: null,
|
||||
createdAt: new Date('2025-08-10'),
|
||||
updatedAt: new Date('2025-08-10'),
|
||||
@@ -1752,10 +1752,10 @@ export class MemStorage implements IStorage {
|
||||
status: 'alerte',
|
||||
quantity: 8,
|
||||
unit: 'unités',
|
||||
notes: 'DLC proche, promotion conseillée',
|
||||
notes: 'DLC proche, promotion conseillée' as string | null,
|
||||
location: 'Rayonnage A3',
|
||||
alertThreshold: 3,
|
||||
validatedBy: null,
|
||||
validatedBy: null as string | null,
|
||||
validatedAt: null,
|
||||
createdAt: new Date('2025-08-08'),
|
||||
updatedAt: new Date('2025-08-13'),
|
||||
|
||||
Reference in new issue
Block a user