-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
112 lines (96 loc) · 2.92 KB
/
Copy pathserver.js
File metadata and controls
112 lines (96 loc) · 2.92 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
const express = require('express');
const request = require('request');
const morgan = require('morgan');
const path = require('path');
const cors = require('cors');
const app = express();
const port = process.env.PORT || 6001;
// const portInfo = 3001;
// const portReviews = 8080;
// const portMenu = 3000;
// const portResy = 3002;
// const hostInfo = `http://localhost:${portInfo}`;
// const hostReviews = `http://localhost:${portReviews}`;
// const hostMenu = `http://localhost:${portMenu}`;
// const hostResy = `http://localhost:${portResy}`;
const hostInfo = 'http://ec2-52-53-177-126.us-west-1.compute.amazonaws.com';
const hostReviews = 'http://ec2-18-219-151-31.us-east-2.compute.amazonaws.com';
const hostMenu = 'http://ec2-18-212-129-29.compute-1.amazonaws.com';
const hostResy = 'http://ec2-54-153-45-179.us-west-1.compute.amazonaws.com';
app.use(morgan('dev'));
app.use(cors());
app.use(express.static(path.join(__dirname, 'public')));
app.get('/reservations/timesBookedToday/:restaurant_id', (req, res) => {
request(`${hostResy}${req.originalUrl}`, (err, response, body) => {
if (err) throw err;
res.send(body);
});
});
app.get('/reservations/inventory', (req, res) => {
request(`${hostResy}${req.originalUrl}`, (err, response, body) => {
if (err) throw err;
res.send(body);
});
});
app.get('/restaurant/profile/:restaurant_id', (req, res) => {
request(`${hostInfo}${req.originalUrl}`, (err, response, body) => {
if (err) throw err;
res.send(body);
});
});
app.get('/restaurants/:restaurant_id/menu', (req, res) => {
request(`${hostMenu}${req.originalUrl}`, (err, response, body) => {
if (err) throw err;
res.send(body);
});
});
app.get('/restaurant/:restaurant_id/reviews', (req, res) => {
request(`${hostReviews}${req.originalUrl}`, (err, response, body) => {
if (err) throw err;
res.send(body);
});
});
app.get('/reviews/:review_id', (req, res) => {
request(`${hostReviews}${req.originalUrl}`, (err, response, body) => {
if (err) throw err;
res.send(body);
});
});
app.get('/user/:user_id/reviews', (req, res) => {
request(`${hostReviews}${req.originalUrl}`, (err, response, body) => {
if (err) throw err;
res.send(body);
});
});
app.post('/reviews', (req, res) => {
request({
uri: `${hostReviews}${req.originalUrl}`,
method: 'POST',
body: req.body,
}, (err, response, body) => {
if (err) throw err;
res.send(body);
});
});
app.delete('/reviews/:review_id', (req, res) => {
request({
uri: `${hostReviews}${req.originalUrl}`,
method: 'DELETE',
}, (err, response, body) => {
if (err) throw err;
res.send(body);
});
});
app.patch('/reviews/:review_id', (req, res) => {
request({
uri: `${hostReviews}${req.originalUrl}`,
method: 'PATCH',
body: req.body,
}, (err, response, body) => {
if (err) throw err;
res.send(body);
});
});
app.listen(port, () => {
console.log(`server running at port:${port}`);
});