-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (58 loc) · 1.47 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
const { response } = require('express');
const express = require('express');
const app = express();
const port = 3001;
const merchant_model = require('./merchant_model');
app.use(express.json());
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS');
res.setHeader(
'Access-Control-Allow-Headers',
'Content-Type, Access-Control-Allow-Headers'
);
next();
});
// app.get('/filter', (req, res) => {
// merchant_model
// .productFilter()
// .then((response) => {
// res.status(200).send(response);
// })
// .catch((error) => {
// res.status(500).send(error);
// });
// });
app.get('/', (req, res) => {
merchant_model
.getMerchants()
.then((response) => {
res.status(200).send(response);
})
.catch((error) => {
res.status(500).send(error);
});
});
app.post('/merchants', (req, res) => {
merchant_model
.createMerchant(req.body)
.then((response) => {
res.status(200).send(response);
})
.catch((error) => {
res.status(500).send(error);
});
});
app.delete('/merchants/:id', (req, res) => {
merchant_model
.deleteMerchant(req.params.id)
.then((response) => {
res.status(200).send(response);
})
.catch((error) => {
res.status(500).send(error);
});
});
app.listen(port, () => {
console.log(`App running on port ${port}.`);
});