interstellar_ai/app/backend/weather.ts

22 lines
665 B
TypeScript
Raw Normal View History

2024-10-09 16:36:08 +02:00
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 });
return success;
} catch (error) {
postMessage({ status: 500, success: false });
console.log(error)
return "";
}
};