-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
113 lines (89 loc) · 4.08 KB
/
index.html
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
<!doctype html>
<html>
<head>
<!-- those are demonstrated cases -->
<script async type="module" src="https://cors-server.netlify.app/js-whitelist/module.js" crossorigin="use-credentials" ></script>
<script async type="module" src="https://cors-server.netlify.app/js-whitelist/module.js" crossorigin="anonymous" ></script>
<script async type="module" src="https://cors-server.netlify.app/js-whitelist/module.js" crossorigin="" ></script>
<script async type="module" src="https://cors-server.netlify.app/js-whitelist/module.js" ></script>
<script async src="https://cors-server.netlify.app/js-whitelist/main.js" crossorigin="anonymous" ></script>
<script async src="https://cors-server.netlify.app/js-whitelist/main.js" ></script>
<script async type="module" src="https://cors-server.netlify.app/js-public/module.js" crossorigin="anonymous" ></script>
<script async type="module" src="https://cors-server.netlify.app/js-public/module.js" ></script>
<script async src="https://cors-server.netlify.app/js-public/main.js" crossorigin="anonymous" ></script>
<script async src="https://cors-server.netlify.app/js-public/main.js" ></script>
<script async type="module" src="https://cors-server.netlify.app/js/module.js" crossorigin="anonymous" ></script>
<script async type="module" src="https://cors-server.netlify.app/js/module.js" ></script>
<script async src="https://cors-server.netlify.app/js/main.js" crossorigin="anonymous" ></script>
<script async src="https://cors-server.netlify.app/js/main.js" ></script>
<script async type="module" src="./js/module.js" ></script>
<script async src="./js/main.js" ></script>
<!-- // -->
<style>
.script::before { content: "\21BB"; padding:0 6px 0 0; }
.error::before { content: "\2715"; color: red; }
.load::before { content: "\2713"; color: green; }
li { list-style-type: none; }
pre>p { margin: auto; }
</style>
<!-- utilities -- yes, it is polluting the global namespace... -->
<script>
// input can be an element or a string
const toHtml = input => ( input.outerHTML || input )
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
function log() {
document.querySelector("#logs")
.appendChild( document.createElement("p") )
.innerHTML = toHtml( [...arguments].map( arg => arg.outerHTML || arg ).join(" ") );
}
</script>
</head>
<body>
<h1>This is a page demonstrating CORS</h1>
<p>
The cross domain server configuration can be found <a href="https://github.com/swiing/cors-server/blob/68905f12c4af533929cf2ac9fdae3ac0e4461bb2/netlify.toml#L5">here</a>.
</p>
<p>
The source code can be found on <a href="https://github.com/swiing/cors-example">github</a>.
</p>
<hr>
<section id="test">
<h2>Test cases</h2>
<ul></ul>
</section>
<hr>
<pre id="logs">
<h2>Logs</h2>
</pre>
<!-- end of displayed document -->
<template id="scriptTest">
<li><span class="script"></span></li>
</template>
<script>
(function() {
const scripts = new WeakMap();
const template = document.querySelector("#scriptTest");
function result() {
const evtType = arguments[0].type;
const scriptElt = arguments[0].target;
scripts.get( scriptElt ).classList.add( evtType );
log( scriptElt, "got", evtType );
}
for( let scriptElt of document.getElementsByTagName("script") )
if( scriptElt.src ) {
let elt = document.importNode( template.content, true );
let scriptDiv = elt.querySelector(".script");
scripts.set( scriptElt, scriptDiv );
scriptElt.addEventListener( "load", result );
scriptElt.addEventListener( "error", result );
scriptDiv.innerHTML = toHtml( scriptElt );
document.querySelector("ul").appendChild( elt );
}
}());
</script>
</body>
</html>