Set up cors and env variables

This commit is contained in:
Guntis Smaukstelis
2023-05-14 23:01:36 +03:00
parent 16c9714f8a
commit 851229ce9b
5 changed files with 46 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
VITE_API_HOST=http://localhost:8080
+1
View File
@@ -0,0 +1 @@
VITE_API_HOST=https://weather-tool.fly.dev
+5
View File
@@ -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
+35
View File
@@ -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>
)
}