Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarungupta18 committed Jul 17, 2024
1 parent e296c69 commit 5e16530
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions Client/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_BASE_URL="http://localhost:4000/api"
2 changes: 1 addition & 1 deletion Client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import PlacePage from './pages/PlacePage'
import BookingsPage from './pages/BookingsPage'
import BookingPage from './pages/BookingPage'

axios.defaults.baseURL = 'http://localhost:4000'
axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL;
axios.defaults.withCredentials = true

function App() {
Expand Down
3 changes: 2 additions & 1 deletion api/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
MONGO_URL= 'mongodb+srv://booking:tarun12345@cluster0.a31k2pa.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0'
CLOUD_NAME=dygmya3an
CLOUD_API_KEY=365397738923551
CLOUD_API_SECRET=E9n2Lix1o7Xy09UmlCubx7pKHug
CLOUD_API_SECRET=E9n2Lix1o7Xy09UmlCubx7pKHug

30 changes: 15 additions & 15 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function main() {
await mongoose.connect(process.env.MONGO_URL);
}

app.get("/test", (req, res) => {
app.get("/api/test", (req, res) => {
res.json("test ok");
});

Expand All @@ -52,7 +52,7 @@ function getUserDataFromReq(req) {
})
}

app.post("/register", async (req, res) => {
app.post("/api/register", async (req, res) => {
const { name, email, password } = req.body;
console.log({ name });
try {
Expand All @@ -67,7 +67,7 @@ app.post("/register", async (req, res) => {
}
});

app.post('/login', async (req, res) => {
app.post('/api/login', async (req, res) => {
const { email, password } = req.body;
const userDoc = await User.findOne({ email });
if (userDoc) {
Expand All @@ -85,7 +85,7 @@ app.post('/login', async (req, res) => {
}
});

app.get('/profile', (req,res) => {
app.get('/api/profile', (req,res) => {
const { token } = req.cookies;
if (token) {
jwt.verify(token, jwtSecret, {}, async (err, userData) => {
Expand All @@ -105,11 +105,11 @@ app.get('/profile', (req,res) => {
});


app.post('/logout', (req, res) => {
app.post('/api/logout', (req, res) => {
res.cookie('token', '').json(true);
});

app.post('/upload-by-link', async (req, res) => {
app.post('/api/upload-by-link', async (req, res) => {
const { link } = req.body;
console.log(link);
try {
Expand All @@ -126,7 +126,7 @@ app.post('/upload-by-link', async (req, res) => {
});

const photosMiddleware = multer({ storage });
app.post('/upload', photosMiddleware.array('photos', 100), async (req, res) => {
app.post('/api/upload', photosMiddleware.array('photos', 100), async (req, res) => {
const uploadedFiles = [];

for (let i = 0; i < req.files.length; i++) {
Expand Down Expand Up @@ -154,9 +154,9 @@ app.post('/upload', photosMiddleware.array('photos', 100), async (req, res) => {
res.json(uploadedFiles);
});

app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
app.use('/api/uploads', express.static(path.join(__dirname, 'uploads')));

app.post('/places', (req, res) => {
app.post('/api/places', (req, res) => {
const { token } = req.cookies;
const { title, address, addedPhotos, description, perks, extraInfo, checkIn, checkOut, maxGuests, price } = req.body;
jwt.verify(token, jwtSecret, {}, async (err, userData) => {
Expand All @@ -171,20 +171,20 @@ app.post('/places', (req, res) => {
})
})

app.get('/user-places', (req, res) => {
app.get('/api/user-places', (req, res) => {
const { token } = req.cookies;
jwt.verify(token, jwtSecret, {}, async (err, userData) => {
const { id } = userData;
res.json(await Place.find({ owner: id }));
})
})

app.get('/places/:id', async (req, res) => {
app.get('/api/places/:id', async (req, res) => {
const { id } = req.params;
res.json(await Place.findById(id));
})

app.put('/places', async (req, res) => {
app.put('/api/places', async (req, res) => {
const { token } = req.cookies;
const {
id, title, address, addedPhotos,
Expand All @@ -205,11 +205,11 @@ app.put('/places', async (req, res) => {
});
});

app.get('/places', async (req, res) => {
app.get('/api/places', async (req, res) => {
res.json(await Place.find());
});

app.post('/bookings', async (req, res) => {
app.post('/api/bookings', async (req, res) => {
const userData = await getUserDataFromReq(req);
const {
place, checkIn, checkOut, numberOfGuests, name, phone, price
Expand All @@ -225,7 +225,7 @@ app.post('/bookings', async (req, res) => {



app.get('/bookings', async (req, res) => {
app.get('/api/bookings', async (req, res) => {
const userData = await getUserDataFromReq(req);
res.json(await Booking.find({ user: userData.id }).populate('place'));
});
Expand Down

0 comments on commit 5e16530

Please sign in to comment.