chore: add example env file, improve documentation and code comments
This commit is contained in:
13
server.js
13
server.js
@@ -8,20 +8,17 @@ require('dotenv').config();
|
||||
const app = express();
|
||||
const port = process.env.SERVER_PORT || 3000;
|
||||
|
||||
// add logging for troubleshooting
|
||||
app.use((req, res, next) => {
|
||||
console.log(`Incoming request: ${req.method} ${req.url}`);
|
||||
next();
|
||||
});
|
||||
|
||||
// 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)
|
||||
const STATIC_DIR = process.env.STATIC_DIR || 'public'
|
||||
app.use(express.static(path.join(__dirname, STATIC_DIR)));
|
||||
|
||||
// Database connection pool setup using environment variables for security
|
||||
// Setup database connection pool using environment variables
|
||||
const pool = new Pool({
|
||||
user: process.env.DB_USER,
|
||||
host: process.env.DB_HOST,
|
||||
@@ -30,7 +27,7 @@ const pool = new Pool({
|
||||
port: process.env.DB_PORT,
|
||||
});
|
||||
|
||||
// Nodemailer transporter setup for sending emails
|
||||
// Configure Nodemailer for sending emails via Brevo relay
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: process.env.EMAIL_HOST,
|
||||
port: 2525,
|
||||
@@ -43,17 +40,11 @@ const transporter = nodemailer.createTransport({
|
||||
});
|
||||
|
||||
const contactController = require('./controllers/contactController')(pool, transporter);
|
||||
|
||||
// Import the security middleware
|
||||
const securityMw = require('./middleware/securityMw');
|
||||
|
||||
// Import contactRoutes and contactController, and pass in securityMw
|
||||
const contactRoutes = require('./routes/contactRoutes')(contactController, securityMw);
|
||||
|
||||
// Use contactRoutes to connect the modular router to the main app
|
||||
app.use('/api', contactRoutes);
|
||||
|
||||
// Start the server
|
||||
app.listen(port, () => {
|
||||
console.log(`Server listening at http://localhost:${port}`);
|
||||
});
|
Reference in New Issue
Block a user