-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
79 lines (70 loc) · 1.79 KB
/
Copy pathindex.html
File metadata and controls
79 lines (70 loc) · 1.79 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
<html>
<head>
<title>CORS Anywhere Example</title>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="key.js"></script>
<style>
pre {
white-space: normal;
background-color: #f1f1f1;
}
</style>
</head>
<body>
<div>
<h1>Without Proxy</h1>
<pre class="without-proxy"></pre>
</div>
<div>
<h1>With Proxy</h1>
<pre class="with-proxy"></pre>
</div>
<script>
function logToDOM(message, dest) {
$(dest).html(message);
}
const apiKey = window.apiKey;
const yelpUrl = 'https://api.yelp.com/v3/businesses/search?location=jersey+city,nj';
const proxyUrl = 'https://shielded-hamlet-43668.herokuapp.com/';
$.ajax({
url: yelpUrl,
headers: {
authorization: 'Bearer ' + apiKey
}
})
.done(response => {
console.log(response);
const message = JSON.stringify(response);
const container = document.querySelector('.without-proxy');
logToDOM(message, container);
})
.catch(error => {
console.error(error);
const message = JSON.stringify(error);
const container = document.querySelector('.without-proxy');
logToDOM(message, container);
});
$.ajax({
url: proxyUrl + yelpUrl,
headers: {
authorization: 'Bearer ' + apiKey
}
})
.done(response => {
console.log(response);
const message = JSON.stringify(response);
const container = document.querySelector('.with-proxy');
logToDOM(message, container);
})
.catch(error => {
console.error(error);
const message = JSON.stringify(error);
const container = document.querySelector('.with-proxy');
logToDOM(message, container);
});
</script>
</body>
</html>