We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4a812e2 commit 61e18deCopy full SHA for 61e18de
src/add-api.html
@@ -19,7 +19,7 @@
19
<script type="text/javascript">
20
var form = document.getElementById('add_api_form');
21
form.onsubmit = addApi;
22
- function addApi(e) {
+ async function addApi(e) {
23
e.preventDefault();
24
25
try {
@@ -41,6 +41,22 @@
41
alert(ex.message);
42
return false;
43
}
44
+ try {
45
+ const res = await fetch(`https://cors.redoc.ly/${form.url.value}`,
46
+ {method:'head'});
47
+ const ct = res.headers.get('content-type');
48
+ if (res.status >= 400) {
49
+ alert(`Error ${res.status} accessing that URL`);
50
+ return false;
51
+ }
52
+ if (ct && ct.startsWith('text/html')) {
53
+ alert('That looks like a web-page, not a machine-readable API definition');
54
+ return(false);
55
56
57
+ catch (ex) {
58
+ console.log(ex.message);
59
60
61
var details = {
62
format: form['spec-format'].value,
0 commit comments