Set up cors and env variables
This commit is contained in:
@@ -0,0 +1 @@
|
||||
VITE_API_HOST=http://localhost:8080
|
||||
@@ -0,0 +1 @@
|
||||
VITE_API_HOST=https://weather-tool.fly.dev
|
||||
@@ -2,11 +2,16 @@ import type { Component } from 'solid-js';
|
||||
|
||||
import logo from './assets/logo.svg';
|
||||
import styles from './css/App.module.css';
|
||||
import { FetchedDates } from './FetchedDates';
|
||||
|
||||
console.log("env:", import.meta.env.MODE);
|
||||
console.log("api host:", import.meta.env.VITE_API_HOST);
|
||||
|
||||
const App: Component = () => {
|
||||
return (
|
||||
<div class={styles.App}>
|
||||
<header class={styles.header}>
|
||||
<FetchedDates />
|
||||
<img src={logo} class={styles.logo} alt="logo" />
|
||||
<p>
|
||||
Weather tool web
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { createResource } from "solid-js";
|
||||
|
||||
const apiHost = import.meta.env.VITE_API_HOST;
|
||||
|
||||
export function FetchedDates() {
|
||||
const fetchDates = async () => {
|
||||
const response = await fetch(`${apiHost}/api/show/all_dates`);
|
||||
const json = await response.json();
|
||||
return json;
|
||||
}
|
||||
|
||||
const [datesResource] = createResource(fetchDates);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{ datesResource.loading && (
|
||||
<div>Loading dates</div>
|
||||
)}
|
||||
{ datesResource.error && (
|
||||
<div>Error while loading dates: ${datesResource.error}</div>
|
||||
)}
|
||||
{ datesResource() && (
|
||||
<ul>
|
||||
{ (datesResource() as any).map((date: any) => item(date))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function item(date: any) {
|
||||
return (
|
||||
<li>{date}</li>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user