From 63cfd936b545283914a9e1438bdc4945be7852d4 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Tue, 4 Jan 2022 23:27:23 -0500 Subject: [PATCH] setup local hosting --- api/Makefile | 2 +- api/src/api/app.py | 19 ++++++++++------- api/web | 2 +- webapp/package.json | 1 + webapp/src/apiService/automations.ts | 1 - webapp/src/apiService/base.ts | 21 ++++++++++++------- webapp/src/apiService/index.ts | 2 +- webapp/src/apiService/paths.ts | 4 ++-- .../src/components/SequenceNodes/positions.ts | 1 - 9 files changed, 31 insertions(+), 22 deletions(-) diff --git a/api/Makefile b/api/Makefile index 4583d1c..5980700 100644 --- a/api/Makefile +++ b/api/Makefile @@ -43,5 +43,5 @@ clean: run-local: rm -f web - ln -s ../web/dist web + ln -s ../webapp/build web USE_EXAMPLE_REPO=1 uvicorn src.app:app diff --git a/api/src/api/app.py b/api/src/api/app.py index 1c7306e..2e8fc99 100644 --- a/api/src/api/app.py +++ b/api/src/api/app.py @@ -7,14 +7,17 @@ from .routes import ping, automations def make_app(automation_mgr: AutomationManager) -> FastAPI: app = FastAPI() - # app.mount( - # "/web", - # StaticFiles( - # directory=ROOT_FOLDER / "web", - # html=True, - # ), - # name="web", - # ) + if (ROOT_FOLDER / "web").exists(): + app.mount( + "/web", + StaticFiles( + directory=ROOT_FOLDER / "web", + html=True, + ), + name="web", + ) + else: + print("WARN: could not find web folder") app.include_router(ping.router, prefix="/ping") app.include_router(automations.make_automation_router(automation_mgr), prefix="/automations") diff --git a/api/web b/api/web index 4315e28..d074fc2 120000 --- a/api/web +++ b/api/web @@ -1 +1 @@ -../web/dist \ No newline at end of file +../webapp/build \ No newline at end of file diff --git a/webapp/package.json b/webapp/package.json index bcd5d73..5ab8c02 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -2,6 +2,7 @@ "name": "webapp", "version": "0.1.0", "private": true, + "homepage": "/web", "dependencies": { "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", diff --git a/webapp/src/apiService/automations.ts b/webapp/src/apiService/automations.ts index c10dd20..3a90bab 100644 --- a/webapp/src/apiService/automations.ts +++ b/webapp/src/apiService/automations.ts @@ -12,7 +12,6 @@ export const makeAutomationAPI = (api: API) => ({ offset, limit, } }); - console.log({ list: data }); return data; }, async update({index, auto}: {index: number, auto: AutomationData}) { diff --git a/webapp/src/apiService/base.ts b/webapp/src/apiService/base.ts index 1c14d2f..2529dd9 100644 --- a/webapp/src/apiService/base.ts +++ b/webapp/src/apiService/base.ts @@ -1,4 +1,4 @@ -import { APIRequest, APIResponse } from "./types"; +import { APIRequest, APIResponse } from './types'; export interface API { makeCall: (req: APIRequest) => Promise>; @@ -9,19 +9,26 @@ export const makeRemoteAPI = (baseURL: string): API => ({ method = "POST", data={} }) { - const reply = await fetch(baseURL + "/" + path, { + const reply = await fetch(baseURL + path, { method, + headers: { + "Content-Type": "application/json" + }, body: JSON.stringify(data), }); + let response: APIResponse; if (reply.status === 200) { - return { + response = { ok: true, data: await reply.json(), } + } else { + response = { + ok: false, + error: await reply.text(), + } + console.error(response) } - return { - ok: false, - error: await reply.text(), - } + return response } }) diff --git a/webapp/src/apiService/index.ts b/webapp/src/apiService/index.ts index 5883d62..b375ab3 100644 --- a/webapp/src/apiService/index.ts +++ b/webapp/src/apiService/index.ts @@ -5,7 +5,7 @@ import { useAPIService } from './core'; import {useMockAPI} from "./mock"; export const useConnectedApiService = () => useAPIService( - makeAutomationAPI(makeRemoteAPI("/api/v1")) + makeAutomationAPI(makeRemoteAPI("/automations")) ); export const useMockApiService = (initialAutos: AutomationData[]) => useAPIService( makeAutomationAPI(useMockAPI(initialAutos)) diff --git a/webapp/src/apiService/paths.ts b/webapp/src/apiService/paths.ts index cb444a1..3bd6ff8 100644 --- a/webapp/src/apiService/paths.ts +++ b/webapp/src/apiService/paths.ts @@ -1,4 +1,4 @@ -export const AUTOMTAION_ROOT = '/automations' as const; -export const AUTOMTAION_LIST = `${AUTOMTAION_ROOT}/list` as const; +export const AUTOMTAION_ROOT = '/' as const; +export const AUTOMTAION_LIST = `${AUTOMTAION_ROOT}list` as const; diff --git a/webapp/src/components/SequenceNodes/positions.ts b/webapp/src/components/SequenceNodes/positions.ts index 288adb4..124e865 100644 --- a/webapp/src/components/SequenceNodes/positions.ts +++ b/webapp/src/components/SequenceNodes/positions.ts @@ -27,7 +27,6 @@ function* dealWithNested( p2: innerStartLoc, direction: '1->2', } - console.log(onRemove) if (onEdit) { yield { type: 'circle',