Skip to content

Commit 4cf9d9d

Browse files
Updated commit
1 parent f53882a commit 4cf9d9d

7 files changed

Lines changed: 15 additions & 56 deletions

File tree

backend/app.js

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,24 @@
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-
301
import express from "express";
312
import cors from "cors";
323
import dotenv from "dotenv";
334
import chatBotRouter from "./routes/chatbot.js";
345

35-
dotenv.config(); // Load environment variables from .env
6+
dotenv.config(); // Load environment variables from .env
367

378
const app = express();
389
const port = process.env.PORT || 3000;
3910

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
4112
app.use(express.json());
4213
app.use(express.urlencoded({ extended: true }));
4314

44-
// Use the chatbot route
15+
// Use the chatbot route
4516
app.use("/api/chatbot", chatBotRouter);
4617

47-
// Error-handling middleware
18+
// Error-handling middleware
4819
app.use((err, req, res, next) => {
4920
if (err instanceof SyntaxError && err.status === 400 && "body" in err) {
50-
console.error("Bad JSON:", err.message);
21+
console.error("Bad JSON:", err.message);
5122
return res.status(400).json({ success: false, message: "Invalid JSON payload" });
5223
}
5324
next();

backend/routes/chatbot.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const router = express.Router();
77
const API_KEY = "ENTER YOUR GOOGLE API KEY HERE"; // Replace with process.env.GOOGLE_API_KEY if using environment variables
88

99
if (!API_KEY) {
10-
console.error("ERROR: Google API key is missing.");
10+
console.error("ERROR: Google API key is missing.");
1111
throw new Error("Google API key is missing.");
1212
}
1313

@@ -25,15 +25,15 @@ router.post("/", async (req, res) => {
2525
try {
2626
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
2727

28-
// Corrected generateContent method
28+
// Corrected generateContent method
2929
const result = await model.generateContent([{ text }]);
3030

31-
// Extract response safely
31+
// Extract response safely
3232
const response = result.response.text();
3333
console.log(response);
3434
res.json({ success: true, response });
3535
} catch (error) {
36-
console.error("🔥 Error in /api/chatbot route:", error.stack);
36+
console.error("Error in /api/chatbot route:", error.stack);
3737
res.status(500).json({ success: false, message: "Failed to generate content." });
3838
}
3939
});

frontend/README.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

frontend/src/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818

1919
.title {
20-
font-size: 5rem; /* 🔥 Increase size to make it stand out */
20+
font-size: 5rem;
2121
font-weight: bold;
2222
text-transform: uppercase;
2323
margin-bottom: 10px;

frontend/src/App.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react"; // Ensure useState is imported
1+
import React, { useState } from "react"; // Ensure useState is imported
22
import Form from "./components/Form";
33
import WorkoutPlan from "./components/WorkoutPlan";
44
import "./App.css";
@@ -24,7 +24,7 @@ function App() {
2424

2525
<main>
2626
<Form setWorkoutPlan={setWorkoutPlan} />
27-
{workoutPlan !== null && <WorkoutPlan plan={workoutPlan} />} {/* Fix: Ensure `workoutPlan` is checked properly */}
27+
{workoutPlan !== null && <WorkoutPlan plan={workoutPlan} />} {/* Fix: Ensure `workoutPlan` is checked properly */}
2828
</main>
2929

3030
<footer className="footer">

frontend/src/components/Form.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ const Form = ({ setWorkoutPlan }) => {
3939
}
4040

4141
const data = await response.json();
42-
console.log("Backend Response:", data);
42+
console.log("Backend Response:", data);
4343

44-
setWorkoutPlan(data.response || "No workout plan received."); // Corrected key
44+
setWorkoutPlan(data.response || "No workout plan received."); // Corrected key
4545
} catch (error) {
4646
console.error("🚨 API Error:", error);
4747
setError(error.message);

frontend/src/components/WorkoutPlan.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.workout-plan {
2-
max-width: 800px; /* Adjust the max width */
2+
max-width: 800px;
33
margin: auto;
44
padding: 20px;
55
background: #ffffff;

0 commit comments

Comments
 (0)