🐛 Fixes CORS and creating triggers
This commit is contained in:
@@ -162,7 +162,7 @@
|
||||
<div class="container">
|
||||
<h1>Setra</h1>
|
||||
|
||||
<form class="create-form">
|
||||
<form onsubmit="createTrigger(event)" class="create-form">
|
||||
<label for="name-input">Name:</label>
|
||||
<input id="name-input" type="text">
|
||||
|
||||
@@ -174,7 +174,6 @@
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Created at</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -190,7 +189,7 @@
|
||||
</table>
|
||||
|
||||
<div class="dialog" id="dialog">
|
||||
<form onsubmit="saveAPIKey(Event)">
|
||||
<form onsubmit="saveAPIKey(event)">
|
||||
<label for="api-key-input">API key:</label>
|
||||
<input id="api-key-input" type="password">
|
||||
|
||||
@@ -221,13 +220,20 @@
|
||||
return;
|
||||
}
|
||||
|
||||
fetch("http://localhost:8000/tracker", {
|
||||
fetch(`${window.location.origin}/tracker`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: apiKey,
|
||||
}
|
||||
}).then((res) => {
|
||||
res.json().then((trackers) => {
|
||||
document.getElementById("tracker-table").innerHTML = `
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Created at</th>
|
||||
</tr>`;
|
||||
|
||||
trackers.forEach((tracker) => {
|
||||
document.getElementById("tracker-table").innerHTML += `
|
||||
<tr>
|
||||
@@ -255,7 +261,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`http://localhost:8000/tracker/${id}/hits`, {
|
||||
fetch(`${window.location.origin}/tracker/${id}/hits`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: apiKey,
|
||||
@@ -286,6 +292,27 @@
|
||||
}).catch((err) => alert(`Couldn't fetch hits: ${err}`));
|
||||
}
|
||||
|
||||
function createTrigger(event) {
|
||||
event.preventDefault();
|
||||
const apiKey = localStorage.getItem("api-key");
|
||||
if (!apiKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
const name = document.getElementById("name-input").value;
|
||||
fetch(`${window.location.origin}/tracker`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({name: name}),
|
||||
headers: {
|
||||
Authorization: apiKey,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
}).then(async (res) => {
|
||||
console.log(await res.text());
|
||||
loadTriggers();
|
||||
}).catch((err) => alert(`Couldn't create trigger: ${err}`));
|
||||
}
|
||||
|
||||
function copyLink(id) {
|
||||
navigator.clipboard.writeText(`http://localhost:8000/image/${id}`).catch((err) => alert(`Couldn't copy: ${err}`));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user