-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
122 lines (108 loc) · 2.8 KB
/
Copy pathserver.js
File metadata and controls
122 lines (108 loc) · 2.8 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const express = require('express');
const morgan = require('morgan');
const path = require('path');
const app = express();
const cors = require('cors');
const Promise = require("bluebird");
const rp = require('request-promise');
const port = process.env.PORT || 1337;
app.use(morgan('dev'));
app.use(cors());
app.use(express.static(path.join(__dirname, 'public')));
const restaurantInfoUrl = 'http://ec2-52-53-177-126.us-west-1.compute.amazonaws.com';
const resyUrl = 'http://ec2-54-153-45-179.us-west-1.compute.amazonaws.com';
const reviewsUrl = 'http://ec2-18-219-151-31.us-east-2.compute.amazonaws.com';
const menuUrl = 'http://ec2-18-212-129-29.compute-1.amazonaws.com';
app.get('/restaurant/profile/:restaurant_id', (req, res) => {
rp(`${restaurantInfoUrl}/restaurant/profile/${req.params.restaurant_id}`)
.then((body) => {
res.send(body);
})
.catch((e) => {
throw(e);
});
});
app.get('/reservations/timesBookedToday/:restaurant_id', (req, res) => {
rp(`${resyUrl}/reservations/timesBookedToday/${req.params.restaurant_id}`)
.then((body) => {
res.send(body);
})
.catch((e) => {
throw(e);
});
});
app.get('/reservations/inventory', (req, res) => {
rp(`${resyUrl}/${req.originalUrl}`)
.then((body) => {
res.send(body);
})
.catch((e) => {
throw(e);
});
});
app.get('/restaurants/:restaurant_id/menu', (req, res) => {
rp(`${menuUrl}/restaurants/${req.params.restaurant_id}/menu`)
.then((body) => {
res.send(body);
})
.catch((e) => {
throw(e);
});
});
app.get('/restaurant/:restaurant_id/reviews', (req, res) => {
rp(`${reviewsUrl}/restaurant/${req.params.restaurant_id}/reviews`)
.then((body) => {
res.send(body);
})
.catch((e) => {
throw(e);
});
});
app.get('/reviews/:review_id', (req, res) => {
rp(`${reviewsUrl}/reviews/${req.params.review_id}`)
.then((body) => {
res.send(body);
})
.catch((e) => {
throw(e);
});
});
app.get('/user/:user_id/reviews', (req, res) => {
rp(`${reviewsUrl}/user/${req.params.user_id}/reviews`)
.then((body) => {
res.send(body);
})
.catch((e) => {
throw(e);
});
});
app.post('/reviews', (req, res) => {
rp(`${reviewsUrl}/reviews`)
.then((body) => {
res.send(body);
})
.catch((e) => {
throw(e);
});
});
app.delete('/reviews/:review_id', (req, res) => {
rp(`${reviewsUrl}/reviews/${req.params.review_id}`)
.then((body) => {
res.send(body);
})
.catch((e) => {
throw(e);
});
});
app.patch('/reviews/:review_id', (req, res) => {
rp(`${reviewsUrl}/reviews/${req.params.review_id}`)
.then((body) => {
res.send(body);
})
.catch((e) => {
throw(e);
});
});
app.listen(port, () => {
console.log(`server running at: http://localhost:${port}`);
});