forked from Brayton-Lordianto/DivHacks-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (37 loc) · 1.27 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
require('./model');
const path = require('path');
const express = require('express');
const cors = require('cors');
console.log('environment ', process.env.ENVIRONMENT)
console.log('PORT ', process.env.PORT)
console.log('MONGO_CONNECTION_STRING ', process.env.MONGODB_URI)
require('dotenv').config({ path: "./config.env" });
const FoodMgmt = require('./crud/food.mgmt');
const app = express();
const port = process.env.PORT || 3080;
app.use(cors());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, '../build')));
app.use(express.json());
// get foods
app.put('/api/get', (req, res) => {
FoodMgmt.getFoods().then(data => res.json(data));
});
// create foods
app.post('/api/create', (req, res) => {
FoodMgmt.createFood(req.body.food).then(data => res.json(data));
});
// update foods
app.post('/api/update', (req, res) => {
FoodMgmt.updateFood(req.body.foodId, req.body.updateDetails).then(data => res.json(data));
});
// delete foods
app.post('/api/delete', (req, res) => {
FoodMgmt.deleteFood(req.body.foodId).then(data => res.json(data));
});
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '../build/index.html'));
});
app.listen(port, () => {
console.log(`Server listening on the port ${port}`);
})