source: backend/server.js@ b612ab1

Last change on this file since b612ab1 was b612ab1, checked in by Nace Gjorgjievski <nace.gorgievski123@…>, 23 months ago

Basic functions added

  • Property mode set to 100644
File size: 815 bytes
Line 
1import express from "express";
2import data from "./data.js";
3
4const app = express();
5
6app.get("/api/products", (req, res) => {
7 res.send(data.products);
8});
9
10app.get("/api/products/slug/:slug", (req, res) => {
11 const product = data.products.find((x) => x.slug === req.params.slug);
12 if (product) {
13 res.send(product);
14 } else {
15 res.status(404).send({ message: "Продуктот не е пронајден" });
16 }
17});
18
19app.get("/api/products/:id", (req, res) => {
20 const product = data.products.find((x) => x._id === req.params.id);
21 if (product) {
22 res.send(product);
23 } else {
24 res.status(404).send({ message: "Продуктот не е пронајден" });
25 }
26});
27
28const port = process.env.PORT || 5000;
29app.listen(port, () => {
30 console.log(`serve at http://localhost:${port}`);
31});
Note: See TracBrowser for help on using the repository browser.