typescriptified and also removed hardcoded addresses

This commit is contained in:
Patrick_Pluto 2024-10-03 14:10:21 +02:00
parent 61919ad094
commit 091744d75b
5 changed files with 42 additions and 18 deletions

View file

@ -18,9 +18,12 @@ if all went well, you will get the status 200 in response.data.status
to check if the request was accepted or declined, check response.data.response, it will be either true or false depending on if it worked, or not.
*/
const apiURL = new URL("http://localhost:5000/interstellar_ai/db")
apiURL.hostname = window.location.hostname;
export const sendToDatabase = async (data: any): Promise<boolean> => {
try {
const response = await axios.post("http://localhost:5000/interstellar_ai/db", data);
const response = await axios.post(apiURL.href, data);
const status = response.data.status;
const success = response.data.response;
postMessage({ status, success });
@ -33,7 +36,7 @@ export const sendToDatabase = async (data: any): Promise<boolean> => {
export const sendToDatabaseAndGetString = async (data: any): Promise<string> => {
try {
const response = await axios.post("http://localhost:5000/interstellar_ai/db", data);
const response = await axios.post(apiURL.href, data);
const status = response.data.status;
const success = response.data.response;
postMessage({ status, success });