-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (26 loc) · 986 Bytes
/
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
// create an express app
const express = require("express");
const app = express();
const recipes = require("./recipes.json");
const filter = require("./filter");
// use the express-static middleware
app.use(express.static("public"));
// define the first route
app.get("/", function (req, res) {
let returnRecipes = [...recipes];
const { name, includeIngredients, excludeIngredients } = req.query;
if (!!name) {
returnRecipes = filter.byName(returnRecipes, name);
}
if (!!includeIngredients) {
parsedIngredients = includeIngredients.split(",");
returnRecipes = filter.byIncludedIngredients(returnRecipes, parsedIngredients);
}
if (!!excludeIngredients) {
parsedIngredients = excludeIngredients.split(",");
returnRecipes = filter.byExcludedIngredients(returnRecipes, parsedIngredients);
}
res.send(returnRecipes);
});
// start the server listening for requests
app.listen(process.env.PORT || 3000, () => console.log("Server is running..."));