weather part 1

This commit is contained in:
Patrick_Pluto 2024-10-09 16:36:08 +02:00
parent 12d7ac37fe
commit ef23ef032f
2 changed files with 46 additions and 10 deletions

22
app/backend/weather.ts Normal file
View file

@ -0,0 +1,22 @@
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 "";
}
};