Set up cors and env variables
This commit is contained in:
@@ -15,6 +15,7 @@ import io.circe.syntax._
|
||||
import parse.Aggregate.AggregateValueImplicits.aggregateValueEncoder
|
||||
import parse.Aggregate.{AggregateKey, UserQuery}
|
||||
import fs2.Stream
|
||||
import org.http4s.server.middleware.CORS
|
||||
import org.http4s.server.staticcontent.FileService
|
||||
|
||||
|
||||
@@ -86,9 +87,11 @@ object Server {
|
||||
}
|
||||
}
|
||||
|
||||
val apiRoutesCors = CORS(apiRoutes)
|
||||
|
||||
private val httpApp = Router(
|
||||
"/" -> staticcontent.fileService[IO](FileService.Config("./web/dist")),
|
||||
"/api" -> apiRoutes
|
||||
"/api" -> apiRoutesCors
|
||||
).orNotFound
|
||||
|
||||
def run: Stream[IO, ExitCode] =
|
||||
|
||||
@@ -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