diff --git a/server/src/index.ts b/server/src/index.ts index 63591cc..6a11d1a 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -3,11 +3,10 @@ import cors from "cors"; import bodyParser from "body-parser"; import path from "path"; import dotenv from "dotenv"; -import ConnectDB from "./lib/db.config"; // Ensure `db.config.ts` exports `ConnectDB` -import UserRouter from "./routes/UserRoutes"; // Ensure `UserRoutes` exports `Router` -import SubscriberRouter from "./routes/SubscriberRoutes"; // Ensure `SubscriberRoutes` exports `Router` +import ConnectDB from "./lib/db.config"; +import UserRouter from "./routes/UserRoutes"; +import SubscriberRouter from "./routes/SubscriberRoutes"; -// Load environment variables dotenv.config(); const app: Application = express(); @@ -20,23 +19,19 @@ app.use(bodyParser.json()); app.use("/api/v1/user", UserRouter); app.use("/api/v1/launch", SubscriberRouter); -// Serve an HTML file for the root route app.get("/", (req: Request, res: Response): void => { res.sendFile(path.join(__dirname, "templates", "serverTemplate.html")); }); -// Catch-all route for undefined routes app.use((req: Request, res: Response): void => { res.status(404).json({ message: "Route not found" }); }); -// Global error handler app.use((err: Error, req: Request, res: Response, next: NextFunction): void => { console.error(err.stack); res.status(500).json({ error: "Something went wrong!" }); }); -// Connect to the database const mongoURI: string | undefined = process.env.MONGO_URI; if (!mongoURI) { @@ -52,5 +47,4 @@ ConnectDB(mongoURI) console.error("Database connection failed:", error); }); -// Export the app for Vercel or other platforms export default app;