forked from React-Group/interstellar_ai
weather part 1
This commit is contained in:
parent
12d7ac37fe
commit
ef23ef032f
2 changed files with 46 additions and 10 deletions
22
app/backend/weather.ts
Normal file
22
app/backend/weather.ts
Normal 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 "";
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue