interstellar_ai/app/backend/weather.ts
2024-10-09 20:20:04 +02:00

23 lines
No EOL
726 B
TypeScript

import axios from "axios";
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/weather")
if (typeof window !== 'undefined') {
apiURL.hostname = window.location.hostname;
} else {
apiURL.hostname = "localhost"
}
export const getWeather = async (data: object): Promise<string> => {
try {
const response = await axios.post(apiURL.href, data);
const status = response.data.status;
const success = response.data.response;
postMessage({ status, success });
console.log(JSON.stringify(success))
return JSON.stringify(success);
} catch (error) {
postMessage({ status: 500, success: false });
console.log(error)
return "";
}
};