This commit refactors the entire codebase from a monolithic structure to a modular one. Key changes include: - Extracting core components (e.g., user authentication, data processing, API handlers) into their own distinct modules. - Implementing a new directory structure to support a modular design. - Updating all internal references and import paths to reflect the new architecture. The new structure improves maintainability, scalability, and allows for easier independent development of each module in the future.
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
const nodemailer = require('nodemailer');
|
|
const express = require('express');
|
|
const path = require('path');
|
|
const { Pool } = require('pg');
|
|
const rateLimit = require('express-rate-limit');
|
|
require('dotenv').config();
|
|
const app = express();
|
|
const port = 3000;
|
|
|
|
// Middleware to parse incoming JSON data from the frontend
|
|
app.use(express.json());
|
|
|
|
// Middleware to serve static files (like index.html, styles.css, script.js)
|
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
|
|
// Database connection pool setup using environment variables for security
|
|
const pool = new Pool({
|
|
user: process.env.DB_USER,
|
|
host: process.env.DB_HOST,
|
|
database: process.env.DB_DATABASE,
|
|
password: process.env.DB_PASSWORD,
|
|
port: process.env.DB_PORT,
|
|
});
|
|
|
|
// Nodemailer transporter setup for sending emails
|
|
const transporter = nodemailer.createTransport({
|
|
host: 'smtp-relay.brevo.com',
|
|
port: 2525,
|
|
secure: false,
|
|
requireTLS: true,
|
|
auth: {
|
|
user: process.env.EMAIL_USER,
|
|
pass: process.env.EMAIL_PASS,
|
|
},
|
|
});
|
|
|
|
// Import contactRoutes and contactController
|
|
const contactRoutes = require('./routes/contactRoutes');
|
|
const contactController = require('./controllers/contactController')(pool, transporter);
|
|
|
|
// Use contactRoutes to connect the modular router to the main app
|
|
app.use(contactRoutes);
|
|
|
|
// Start the server
|
|
app.listen(port, () => {
|
|
console.log(`Server listening at http://localhost:${port}`);
|
|
}); |