|
17 | 17 | <script src="./meilisearch.umd.js"></script> |
18 | 18 | <script> |
19 | 19 | ; (async () => { |
| 20 | + let content = '' |
| 21 | + let searchDiv = undefined |
| 22 | + // also works with window.MeiliSearch |
| 23 | + const client = new MeiliSearch({ |
| 24 | + host: 'http://127.0.0.1:7700', |
| 25 | + apiKey: 'masterKey', |
| 26 | + }) |
| 27 | + const UID = "testIndex" |
20 | 28 |
|
21 | 29 | try { |
22 | | - const UID = "testIndex" |
23 | | - |
24 | | - // also works with window.MeiliSearch |
25 | | - const client = new MeiliSearch({ |
26 | | - host: 'http://127.0.0.1:7700', |
27 | | - apiKey: 'masterKey', |
28 | | - }) |
29 | 30 | const task = await client.createIndex(UID) |
30 | 31 | await client.waitForTask(task.uid) |
31 | 32 |
|
|
40 | 41 | indexDiv.innerHTML = index.uid |
41 | 42 | document.body.insertBefore(indexDiv, document.querySelector("#content")); |
42 | 43 |
|
43 | | - const searchDiv = document.createElement("div"); |
| 44 | + searchDiv = document.createElement("div"); |
44 | 45 | searchDiv.setAttribute("id", "search"); |
45 | 46 | const search = await client.index(UID).search() |
46 | | - searchDiv.innerHTML = JSON.stringify(search) |
47 | | - document.body.insertBefore(searchDiv, document.querySelector("#content")); |
48 | | - |
49 | | - const deleteTask = await client.index(UID).delete() |
50 | | - await client.waitForTask(deleteTask.uid) |
| 47 | + content = JSON.stringify(search) |
51 | 48 | } catch (e) { |
52 | 49 | console.error(e); |
| 50 | + content = e.message |
53 | 51 | } |
| 52 | + searchDiv.innerHTML = content |
| 53 | + document.body.insertBefore(searchDiv, document.querySelector("#content")); |
| 54 | + const deleteTask = await client.index(UID).delete() |
| 55 | + await client.waitForTask(deleteTask.uid) |
54 | 56 | })() |
55 | 57 |
|
56 | 58 |
|
|
0 commit comments