-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-ecmwf-ajax
140 lines (128 loc) Β· 6.76 KB
/
test-ecmwf-ajax
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html lang="en">
<head>
<style>
table {
wdith: 100%;
}
iframe, div.iframe {
width: 23vw;
height: 13vw;
}
div.iframe {
background-color: #f1f1f1;
/*padding-top: 45%;*/
text-align: center;
overflow: scroll;
}
</style>
<script>
function getContent(div,url) {
/*const xhr = new XMLHttpRequest();
xhr.onload = function() { //console.info(xhr);
if(xhr.status===200) {
document.getElementById(div).innerHTML = this.responseText;
} else {
document.getElementById(div).innerHTML = xhr.statusText;
}
};
xhr.onerror = function(err) {
document.getElementById(div).innerHTML = xhr.status;
}
xhr.open("GET", url, true);
xhr.withCredentials = true;
xhr.send();*/
fetch(url, {
credentials: 'include'
})
.then(function(response) {
return response.text(); //promise returns text
})
.then(function(text) {
document.getElementById(div).innerHTML = text;
})
.catch(function(error) {
document.getElementById(div).innerHTML = error;
});
}
function postContent(div,url) {
//var authorizationBasic = window.btoa(user + ':' + pass);
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
//xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
//xhr.setRequestHeader('Accept', 'application/json');
//xhr.setRequestHeader('Authorization', 'Basic ' + authorizationBasic);
//xhr.send('token=' + token);
xhr.onreadystatechange = function () {
if(xhr.status===200) {
document.getElementById(div).innerHTML = this.responseText;
} else {
document.getElementById(div).innerHTML = this.statusText;
}
};
}
</script>
</head>
<body>
<h1>Web content sharing tests</h1>
<p>The tests below test the sharing of content across the ecmwf subdomain origins (e.g. www, confluence, and apps).</p>
<p>To test how it works with login you must thoroughly kill all previous *.ecmwf.int auth sessions, then log in on just one of the subdomains (DO NOT visit any other subdomains!) and test the version of this page on that subdomain.</p>
<ul>
<li><a href="https://htmlpreview.github.io/?https://raw.githubusercontent.com/kiden/html/master/test-ecmwf-ajax">External site</a></li>
<li><a href="https://sites.ecmwf.int/intranet/data/tests/test-content-sharing-ajax.html">Sites</a></li>
<li><a href="https://www.ecmwf.int/en/test-content-sharing-ajax">www</a></li>
<li><a href="">apps (tbc)</a></li>
<li><a href="https://confluence.ecmwf.int/display/~adhs/Cross-origin+content+sharing+test+-+XMLHttpRequest">confluence</a></li>
</ul>
<p>Now repeat the tests after establshing a session on all the subdomains.</p>
<p>Then repeat all of those tests across the major browsers our users use - see (opens in new window)</p>
<h1>Ajax requests (with credentials) to content hosted on other servers</h1>
<table>
<tr>
<td>
<p><strong><a href="https://api.ecmwf.int/v1/key/?format=json">π get API key</a></strong></p>
<div class="iframe" id="apitoken"></div>
<script>getContent('apitoken','https://api.ecmwf.int/v1/key/?format=json');</script>
</td>
<td>
<p><strong><a href="https://api.ecmwf.int/v1/services/meteogram/requests/">π post API Meteogram</a>(depends on API key)</strong></p>
<div class="iframe" id="apimeteograms"></div>
<script>postContent('apimeteograms','https://api.ecmwf.int/v1/services/meteogram/requests/');</script>
</td>
<td>
<p><strong><a href=" https://www.ecmwf.int/ecmwf_status/status">get WWW service status</a></strong></p>
<div class="iframe" id="sessions"></div>
<script>getContent('sessions',' https://www.ecmwf.int/ecmwf_status/status');</script>
</td>
<td>
<p><strong><a href="https://sites.ecmwf.int/intranet/data/exchange.json">π get Sites json</a></strong></p>
<div class="iframe" id="siteslists"></div>
<script>getContent('siteslists','https://sites.ecmwf.int/intranet/data/exchange.json');</script>
</td>
</tr>
<tr>
<td>
<p><strong><a href="https://confluence.ecmwf.int/rest/api/content/search?cql=parent=45748339&maxResults=5">π get Conflence API</a></strong></p>
<div class="iframe" id="confluenceapi"></div>
<script>getContent('confluenceapi','https://confluence.ecmwf.int/rest/api/content/search?cql=parent=45748339&maxResults=5');</script>
</td>
<td>
<p><strong><a href="https://jira.ecmwf.int/rest/api/2/search?jql=project%20IN%20(SD,CUS,DSC)&maxResults=5">π get Jira API</a></strong></p>
<div class="iframe" id="jiraapi"></div>
<script>getContent('jiraapi','https://jira.ecmwf.int/rest/api/2/search?jql=project%20IN%20(SD,CUS,DSC)&maxResults=5');</script>
</td>
<td>
<p><strong><a href="https://apps.ecmwf.int/webapps/opencharts-api/v1/packages/opencharts/products/">get Apps Charts</a></strong></p>
<div class="iframe" id="appscharts"></div>
<script>getContent('appscharts','https://apps.ecmwf.int/webapps/opencharts-api/v1/packages/opencharts/products/');</script>
</td>
<td>
<p><strong><a href="">tbc</a></strong></p>
<div class="iframe" id=""></div>
<script></script>
</td>
</tr>
</table>
<div id="logs"></div>
</body>
</html>