Skip to content

Commit

Permalink
Setup backend with mvc architechture added proper routing
Browse files Browse the repository at this point in the history
  • Loading branch information
samar12-rad committed Oct 3, 2024
1 parent 39dc5ab commit 4af9a60
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion backend/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MONGO_URI=your-mongo-uri

This comment has been minimized.

Copy link
@RamakrushnaBiswal

RamakrushnaBiswal Oct 3, 2024

Owner

make the file name as .env.example

and dont push your credentials , just write the MNGO URI

This comment has been minimized.

Copy link
@RamakrushnaBiswal

RamakrushnaBiswal Oct 3, 2024

Owner

make the file name as .env.example

and dont push your credentials , just write the MNGO URI

This comment has been minimized.

Copy link
@samar12-rad

samar12-rad Oct 3, 2024

Author Contributor

Done

MONGO_URI=mongodb+srv://vsamarth1212:[email protected]/
16 changes: 12 additions & 4 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ const port = 3000;
require("dotenv").config();
const mongoose = require("mongoose");

app.use(cors({}));
app.use(
cors({
origin: "*",
})
);

app.use(express.json());

mongoose
.connect(process.env.MONGO_URI)
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("Connected to MongoDB");
})
.catch((error) => {
console.error("Database connection failed:", error);
console.error("Database connection failed:", error.message);
console.error(error.stack);
});

app.post("/api", require("./routes/api"));
app.use("/api", require("./routes/index"));

app.listen(port, () => console.log(`Server is running on port ${port}!`));
7 changes: 0 additions & 7 deletions backend/routes/api.js

This file was deleted.

10 changes: 10 additions & 0 deletions backend/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require("express");

const router = express.Router();

router.use("/reservation", require("./reservationRouter"));
router.get("/", (req, res) => {
res.send("Welcome to the restaurant API!");
});

module.exports = router;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const express = require("express");
const { createReservation } = require("../controller/reservation.controller");
const router = express.Router();

router.post("./create", createReservation);
router.post("/create", createReservation);
router.get("/", (req, res) => {
res.send("Welcome to the restaurant resservation API!");
});

module.exports = router;
2 changes: 1 addition & 1 deletion frontend/src/components/Pages/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function Register() {

const handleSubmit = (e) => {
e.preventDefault();
fetch("http://localhost:3000/create-reservation", {
fetch("http://localhost:3000/api/reservation/create", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down

0 comments on commit 4af9a60

Please sign in to comment.