Skip to content

Commit

Permalink
fix : code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
SSameer20 committed Dec 9, 2024
1 parent 2ca0e3b commit 85ff086
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -52,5 +47,4 @@ ConnectDB(mongoURI)
console.error("Database connection failed:", error);
});

// Export the app for Vercel or other platforms
export default app;

0 comments on commit 85ff086

Please sign in to comment.