Last change
on this file since b612ab1 was b612ab1, checked in by Nace Gjorgjievski <nace.gorgievski123@…>, 2 years ago |
Basic functions added
|
-
Property mode
set to
100644
|
File size:
815 bytes
|
Rev | Line | |
---|
[b612ab1] | 1 | import express from "express";
|
---|
| 2 | import data from "./data.js";
|
---|
| 3 |
|
---|
| 4 | const app = express();
|
---|
| 5 |
|
---|
| 6 | app.get("/api/products", (req, res) => {
|
---|
| 7 | res.send(data.products);
|
---|
| 8 | });
|
---|
| 9 |
|
---|
| 10 | app.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 |
|
---|
| 19 | app.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 |
|
---|
| 28 | const port = process.env.PORT || 5000;
|
---|
| 29 | app.listen(port, () => {
|
---|
| 30 | console.log(`serve at http://localhost:${port}`);
|
---|
| 31 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.