|
1 | | -// import express from "express"; |
2 | | -// import cors from "cors"; |
3 | | -// import chatBotRouter from "./routes/chatbot.js"; |
4 | | -// // ✅ Load environment variables from .env |
5 | | - |
6 | | - |
7 | | -// const app = express(); |
8 | | -// const port = process.env.PORT || 3000; |
9 | | - |
10 | | -// app.use(cors()); |
11 | | -// app.use(express.json()); |
12 | | -// app.use(express.urlencoded({ extended: true })); |
13 | | - |
14 | | -// // ✅ Use the chatbot route |
15 | | -// app.use("/api/chatbot", chatBotRouter); |
16 | | - |
17 | | -// // ✅ Error-handling middleware |
18 | | -// app.use((err, req, res, next) => { |
19 | | -// if (err instanceof SyntaxError && err.status === 400 && "body" in err) { |
20 | | -// console.error("❌ Bad JSON:", err.message); |
21 | | -// return res.status(400).json({ success: false, message: "Invalid JSON payload" }); |
22 | | -// } |
23 | | -// next(); |
24 | | -// }); |
25 | | - |
26 | | -// app.listen(port, () => { |
27 | | -// console.log(`🚀 Server is running on http://localhost:${port}`); |
28 | | -// }); |
29 | | - |
30 | 1 | import express from "express"; |
31 | 2 | import cors from "cors"; |
32 | 3 | import dotenv from "dotenv"; |
33 | 4 | import chatBotRouter from "./routes/chatbot.js"; |
34 | 5 |
|
35 | | -dotenv.config(); // ✅ Load environment variables from .env |
| 6 | +dotenv.config(); // Load environment variables from .env |
36 | 7 |
|
37 | 8 | const app = express(); |
38 | 9 | const port = process.env.PORT || 3000; |
39 | 10 |
|
40 | | -app.use(cors({ origin: "http://localhost:5173" })); // ✅ Adjust this based on frontend URL |
| 11 | +app.use(cors({ origin: "http://localhost:5173" })); // Adjust this based on frontend URL |
41 | 12 | app.use(express.json()); |
42 | 13 | app.use(express.urlencoded({ extended: true })); |
43 | 14 |
|
44 | | -// ✅ Use the chatbot route |
| 15 | +// Use the chatbot route |
45 | 16 | app.use("/api/chatbot", chatBotRouter); |
46 | 17 |
|
47 | | -// ✅ Error-handling middleware |
| 18 | +// Error-handling middleware |
48 | 19 | app.use((err, req, res, next) => { |
49 | 20 | if (err instanceof SyntaxError && err.status === 400 && "body" in err) { |
50 | | - console.error("❌ Bad JSON:", err.message); |
| 21 | + console.error("Bad JSON:", err.message); |
51 | 22 | return res.status(400).json({ success: false, message: "Invalid JSON payload" }); |
52 | 23 | } |
53 | 24 | next(); |
|
0 commit comments