-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
73 lines (64 loc) · 1.67 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const express = require("express");
const bodyParser = require("body-parser");
const multer = require("multer");
const cors = require("cors");
const path = require("path");
const app = express();
const PORT = 5000;
// Middleware
app.use(bodyParser.json());
app.use(cors());
app.use("/uploads", express.static(path.join(__dirname, "uploads")));
// Storage configuration for Multer
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "uploads/");
},
filename: function (req, file, cb) {
cb(null, Date.now() + "-" + file.originalname);
},
});
const upload = multer({ storage });
// API Routes
// Submit a review
app.post("/reviews", upload.single("image"), (req, res) => {
const { name, type, reviewText, rating } = req.body;
const imagePath = req.file ? `/uploads/${req.file.filename}` : null;
// Mock database response
const newReview = {
id: Date.now(),
name,
type,
reviewText,
rating,
imagePath,
};
console.log("New Review Submitted:", newReview);
res.status(201).json({ message: "Review submitted successfully", newReview });
});
// Fetch reviews (mock data for now)
app.get("/reviews", (req, res) => {
const mockReviews = [
{
id: 1,
name: "Labadi Beach",
type: "place",
reviewText: "Amazing beach with great views!",
rating: 4.5,
imagePath: "/uploads/labadi.jpg",
},
{
id: 2,
name: "Frutelli",
type: "product",
reviewText: "Great taste .",
rating: 4.0,
imagePath: null,
},
];
res.json(mockReviews);
});
// Start the server
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});