fix: Resolve TypeError by correcting module dependency injection
This commit fixes a TypeError that occurred because the contactRoutes module was being initialized before the contactController module. The fix involves: - Swapping the initialization order in server.js so the contactController is initialized before contactRoutes. - Modifying contactRoutes.js to accept the initialized contactController as a dependency, rather than requiring it on its own.
This commit is contained in:
@@ -34,10 +34,11 @@ const transporter = nodemailer.createTransport({
|
||||
},
|
||||
});
|
||||
|
||||
// Import contactRoutes and contactController
|
||||
const contactRoutes = require('./routes/contactRoutes');
|
||||
const contactController = require('./controllers/contactController')(pool, transporter);
|
||||
|
||||
// Import contactRoutes and contactController
|
||||
const contactRoutes = require('./routes/contactRoutes')(contactController);
|
||||
|
||||
// Use contactRoutes to connect the modular router to the main app
|
||||
app.use(contactRoutes);
|
||||
|
||||
|
Reference in New Issue
Block a user