-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
64 lines (61 loc) · 1.77 KB
/
server.js
File metadata and controls
64 lines (61 loc) · 1.77 KB
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
64
const express = require('express')
const request = require('request')
const parser = require('body-parser')
const axios = require('axios')
const app = express()
app.use(parser.json())
app.use(express.static(__dirname))
app.get('/products/:id/images', (req, res) => {
request(`http://localhost:3004${req.url}`, (error, response, body) => {
if (error) throw new Error(error)
res.end(body)
})
})
app.get('/productDetails/:id', (req, res) => {
console.log(`http://localhost:3001${req.url}`)
axios.get(`http://localhost:3001${req.url}`)
.then((response) => {
res.send(response.data);
})
.catch((err) => {
console.log('your axios has an error', err)
});
});
app.get('/reviews-module/reviews/:id', (req, res) => {
console.log(`http://localhost:3002${req.url}`);
request(`http://localhost:3002${req.url}`, (error, response, body) => {
if (error) throw new Error(error);
res.end(body);
});
});
app.put('/reviews-module/reviews', (req, res) => {
console.log('req.body', req.body);
axios.put(`http://localhost:3002${req.url}`, req.body)
.then(() => {
res.status(204).end();
})
.catch((err) => {
throw (err);
});
});
app.get('/youMayAlsoLike/:id', (req, res) => {
axios.get(`http://localhost:3003${req.url}`)
.then((response) => {
console.log('this is the response', response.data)
res.send(response.data);
})
.catch((err) => {
console.log('your axios has an error', err)
});
});
app.get('/products/:id/images', (req, res) => {
axios.get(`http://localhost:3004${req.url}`)
.then((response) => {
console.log('this is the response', response.data)
res.send(response.data);
})
.catch((err) => {
console.log('your axios has an error', err)
});
});
app.listen(3000)