2025-03-19 02:09:30 -06:00
|
|
|
const express = require("express");
|
|
|
|
|
const cors = require("cors");
|
|
|
|
|
//Get the db connection
|
|
|
|
|
const db = require("./utils/database");
|
|
|
|
|
|
|
|
|
|
const userRouter = require("./routes/user");
|
|
|
|
|
const productRouter = require("./routes/product");
|
2025-03-29 17:28:09 -06:00
|
|
|
const searchRouter = require("./routes/search");
|
2025-03-19 02:09:30 -06:00
|
|
|
const { generateEmailTransporter } = require("./utils/mail");
|
2025-03-19 12:07:10 -06:00
|
|
|
const {
|
|
|
|
|
cleanupExpiredCodes,
|
|
|
|
|
checkDatabaseConnection,
|
|
|
|
|
} = require("./utils/helper");
|
2025-01-30 13:29:13 -07:00
|
|
|
|
2025-03-11 16:44:25 -06:00
|
|
|
const app = express();
|
2025-03-19 02:09:30 -06:00
|
|
|
|
2025-01-30 13:29:13 -07:00
|
|
|
app.use(cors());
|
2025-03-12 16:13:03 -06:00
|
|
|
app.use(express.json());
|
2025-01-30 13:29:13 -07:00
|
|
|
|
2025-03-12 16:13:03 -06:00
|
|
|
// Configure email transporter for Zoho
|
2025-03-19 02:09:30 -06:00
|
|
|
const transporter = generateEmailTransporter();
|
2025-03-12 16:13:03 -06:00
|
|
|
// Test the email connection
|
|
|
|
|
transporter
|
|
|
|
|
.verify()
|
|
|
|
|
.then(() => {
|
|
|
|
|
console.log("Email connection successful!");
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error("Email connection failed:", error);
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-19 12:07:10 -06:00
|
|
|
//Check database connection
|
|
|
|
|
checkDatabaseConnection(db);
|
|
|
|
|
|
2025-03-19 02:09:30 -06:00
|
|
|
//Routes
|
|
|
|
|
app.use("/api/user", userRouter); //prefix with /api/user
|
|
|
|
|
app.use("/api/product", productRouter); //prefix with /api/product
|
2025-03-29 17:28:09 -06:00
|
|
|
app.use("/api/search_products", searchRouter); //prefix with /api/product
|
2025-03-12 16:13:03 -06:00
|
|
|
|
|
|
|
|
// Set up a scheduler to run cleanup every hour
|
|
|
|
|
setInterval(cleanupExpiredCodes, 60 * 60 * 1000);
|
2025-03-18 18:09:15 -06:00
|
|
|
|
2025-01-30 13:46:49 -07:00
|
|
|
app.listen(3030, () => {
|
2025-03-12 16:13:03 -06:00
|
|
|
console.log(`Running Backend on http://localhost:3030/`);
|
|
|
|
|
console.log(`Send verification code: POST /send-verification`);
|
|
|
|
|
console.log(`Verify code: POST /verify-code`);
|
2025-01-30 13:46:49 -07:00
|
|
|
});
|