-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
97 lines (82 loc) · 2.94 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
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
const express = require('express');
const morgan = require('morgan');
const path = require('path');
const app = express();
const bodyParser = require('body-parser');
const axios = require('axios');
const cors = require('cors');
const port = process.env.PORT || 3000;
app.use(cors());
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/:id', express.static(path.join(__dirname, 'public')));
app.listen(port, () => {
console.log(`server running at: http://localhost:${port}`);
});
//HEADER
app.get('/api/locations/hostels/:id/info', (req, res) => {
const { id } = req.params;
axios
.get(`http://18.191.246.21/api/locations/hostels/${id}/info`)
.then(response => res.send(response.data))
.catch(err => res.status(404).json({ Error: err }));
});
app.get('/api/locations/:id/info', (req, res) => {
const { id } = req.params;
axios
.get(`http://18.191.246.21/api/locations/${id}/info`)
.then(response => res.send(response.data))
.catch(err => res.json({ message: 'Cannot GET /api/locations/:id/info' }));
});
app.get('/api/locations/hostels', (req, res) => {
const { id } = req.params;
axios
.get(`http://18.191.246.21/api/locations/${id}/hostels`)
.then(response => res.send(response.data))
.catch(err => res.json({ message: 'Cannot GET /locations/hostels' }));
});
// OVERVIEW
app.get('/api/overview/:id', (req, res) => {
const { id } = req.params;
axios
.get(`http://54.237.214.214/api/overview/${id}`)
.then(response => res.send(response.data))
.catch(err => res.send(`Cannot get /api/overview/:id, ${err}`));
});
app.get('/api/hostels', (req, res) => {
axios
.get('http://54.237.214.214/api/hostels')
.then(response => res.send(response.data))
.catch(err => res.send(`Cannot get /api/hostels ${err}`));
});
app.get('/api/hostels/:id/info', (req, res) => {
const { id } = req.params;
axios
.get(`http://54.237.214.214/api/hostels/${id}/info`)
.then(response => res.send(response.data))
.catch(err => res.send(`Cannot get /api/hostels/:id/info ${err}`));
});
//BOOKING
app.get('/api/hostels/:id/reservations', (req, res) => {
const { id } = req.params;
axios
.get(`http://13.57.253.197/api/hostels/${id}/reservations`)
.then(response => res.send(response.data))
.catch(err => res.json({ message: 'Cannot GET /api/reviews/overview/id' }));
});
//REVIEWS
app.get('/api/reviews/:id/all', (req, res) => {
const { id } = req.params;
axios
.get(`http://54.172.255.74/api/reviews/${id}/all`)
.then(response => res.send(response.data))
.catch(err => res.status(404).json({ message: 'Cannot GET /api/reviews/id/all' }));
});
app.get('/api/reviews/overview/:id', (req, res) => {
const { id } = req.params;
axios
.get(`http://54.172.255.74/api/reviews/overview/${id}`)
.then(response => res.send(response.data))
.catch(err => res.json({ message: 'Cannot GET /api/reviews/overview/id' }));
});