diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7144ab2f1..caa6df4b3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@
- Add SSL support (#669)
- Rename fieldsFrequency into fieldsDistribution in stats (#719)
- Add support for error code reporting (#703)
+ - Allow the dashboard to query private servers (#732)
## v0.10.1
diff --git a/meilisearch-http/public/interface.html b/meilisearch-http/public/interface.html
index de9d896ab..d869e849c 100644
--- a/meilisearch-http/public/interface.html
+++ b/meilisearch-http/public/interface.html
@@ -94,6 +94,17 @@
This dashboard will help you check the search results with ease.
+
+
+
+
+
+
+
At least a private API key is required for the dashboard to access the indexes list.
+
+
+
+
@@ -158,13 +169,33 @@
return str;
}
- function httpGet(theUrl) {
+ function httpGet(theUrl, apiKey) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", theUrl, false); // false for synchronous request
+ if (apiKey) {
+ xmlHttp.setRequestHeader("x-Meili-API-Key", apiKey);
+ }
xmlHttp.send(null);
return xmlHttp.responseText;
}
+ function refreshIndexList() {
+ // TODO we must not block here
+ let result = JSON.parse(httpGet(`${baseUrl}/indexes`, localStorage.getItem('apiKey')));
+
+ if (!Array.isArray(result)) { return }
+
+ let select = document.getElementById("index");
+ select.innerHTML = '';
+
+ for (index of result) {
+ const option = document.createElement('option');
+ option.value = index.uid;
+ option.innerHTML = index.name;
+ select.appendChild(option);
+ }
+ }
+
let lastRequest = undefined;
function triggerSearch() {
@@ -178,6 +209,11 @@
lastRequest = new XMLHttpRequest();
lastRequest.open("GET", theUrl, true);
+
+ if (localStorage.getItem('apiKey')) {
+ lastRequest.setRequestHeader("x-Meili-API-Key", localStorage.getItem('apiKey'));
+ }
+
lastRequest.onload = function (e) {
if (lastRequest.readyState === 4 && lastRequest.status === 200) {
let sanitizedResponseText = sanitizeHTMLEntities(lastRequest.responseText);
@@ -250,18 +286,18 @@
lastRequest.send(null);
}
- let baseUrl = window.location.origin;
- // TODO we must not block here
- let result = JSON.parse(httpGet(`${baseUrl}/indexes`));
-
- let select = document.getElementById("index");
- for (index of result) {
- const option = document.createElement('option');
- option.value = index.uid;
- option.innerHTML = index.name;
- select.appendChild(option);
+ if (!apiKey.value) {
+ apiKey.value = localStorage.getItem('apiKey');
}
+ apiKey.addEventListener('input', function(e) {
+ localStorage.setItem('apiKey', apiKey.value);
+ refreshIndexList();
+ }, false);
+
+ let baseUrl = window.location.origin;
+ refreshIndexList();
+
search.oninput = triggerSearch;
select.onchange = triggerSearch;