一个快捷查询API Keys的网页
EXAMPLES
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Meilisearch API Example</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
h1 {
color: #333;
}
label {
display: block;
margin: 10px 0 5px;
font-weight: bold;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
button {
background-color: #007bff;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
#keys {
margin-top: 20px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 4px;
padding: 15px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<h1>Meilisearch API Keys</h1>
<label for="apiUrl">API URL:</label>
<input type="text" id="apiUrl" placeholder="https://your-api-url/keys?limit=3">
<label for="apiKey">API Key:</label>
<input type="text" id="apiKey" placeholder="Your Master Key">
<button id="fetchKeys">Fetch Keys</button>
<div id="keys"></div>
<script>
document.getElementById('fetchKeys').addEventListener('click', () => {
const apiUrl = document.getElementById('apiUrl').value;
const apiKey = document.getElementById('apiKey').value;
fetch(apiUrl, {
method: 'GET',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
})
.then(response => {
if (!response.ok) {
throw new Error('Authorization failed or API key missing.');
}
return response.json();
})
.then(data => {
const keysDiv = document.getElementById('keys');
keysDiv.innerHTML = `<pre>${JSON.stringify(data, null, 2)}</pre>`;
})
.catch(error => {
console.error('Error:', error);
document.getElementById('keys').textContent = 'Error: ' + error.message;
});
});
</script>
</body>
</html>