-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (38 loc) · 1014 Bytes
/
index.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
const express =require('express');
const app = express();
const port = process.env.PORT || 5000;
const cors = require('cors');
app.use(cors());
const chief = require('./chef.json');
const recipe = require('./recipe.json');
app.get("/chief", (req,res)=>{
res.send(chief);
console.log(chief)
})
// chief id capture
app.get(("/chief/:id"),(req,res)=>{
const id =parseInt(req.params.id);
const clickChiefCard = chief.find(c=>parseInt(c.id) == id);
res.send(clickChiefCard);
console.log(clickChiefCard)
})
// Recipe Category
app.get("/recipe", (req,res)=>{
res.send(recipe);
console.log(recipe);
})
// Recipe Id Captured
app.get("/recipe/:id", (req,res)=>{
const id = parseInt(req.params.id);
const findRecipe = recipe.find(recipe => parseInt(recipe.chef_category_id) === id);
if(findRecipe){
res.send(findRecipe);
console.log(findRecipe);
}
else{
res.status(404).send("Recipe not found.");
}
})
app.listen(port,()=>{
console.log("apps running ")
})