- clean up

- origins
This commit is contained in:
ari committed 2022-04-15 15:50:33 -04:00
1 parent f6af594a8f
commit 5e345d20e5
8 files changed
+2104 -21

No files matched your search

+9 -1
View File
@@ -1,7 +1,8 @@
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from src.automations.manager import AutomationManager
from src.env import ROOT_FOLDER
from src.env import ROOT_FOLDER, ORIGIN
from .routes import ping, automations
@@ -18,6 +19,13 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI:
)
else:
print("WARN: could not find web folder")
app.add_middleware(
CORSMiddleware,
allow_origins=ORIGIN,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(ping.router, prefix="/ping")
app.include_router(automations.make_automation_router(automation_mgr), prefix="/automations")
+3 -1
View File
@@ -1,7 +1,9 @@
from decouple import config
from email.policy import default
from decouple import config, Csv
from pathlib import Path
ROOT_FOLDER = Path(__file__).parent.parent.absolute()
BUILD_VERSION = config("BUILD_VERSION", "0.0.0")
LOG_LEVEL = config("LOG_LEVEL", "INFO")
ORIGIN = config("ORIGIN", cast=Csv(), default="*")
+5 -4
View File
@@ -8,17 +8,18 @@ export const useAPIService = (
) => {
// state
const [state, setState] = useDefaultApiState();
const {reload, wrapCall} = makeReloadAutomations(automationAPI, state, setState);
const { reload, wrapCall } = makeReloadAutomations(automationAPI, state, setState);
// initial load of autos
useEffect(() => {
reload();
// eslint-disable-next-line
}, []);
return {
state,
removeAutomation: wrapCall(automationAPI.remove),
updateAutomation: wrapCall(automationAPI.update),
removeAutomation: wrapCall(automationAPI.remove),
updateAutomation: wrapCall(automationAPI.update),
}
}
+5 -2
View File
@@ -2,13 +2,16 @@ import { AutomationData } from 'types/automations';
import { makeAutomationAPI } from './automations';
import { makeRemoteAPI } from "./base";
import { useAPIService } from './core';
import {useMockAPI} from "./mock";
import { useMockAPI } from "./mock";
const locationPrefixWeb = window.location.pathname.match(/(.+)\/web/i);
console.log(process.env)
export const useConnectedApiService = () => useAPIService(
makeAutomationAPI(makeRemoteAPI(
(!locationPrefixWeb ? '' : locationPrefixWeb[1]) + "/automations"
process.env.NODE_ENV === 'development' ?
"http://localhost:8000/automations" :
(!locationPrefixWeb ? '' : locationPrefixWeb[1]) + "/automations"
))
);
export const useMockApiService = (initialAutos: AutomationData[]) => useAPIService(
@@ -2,8 +2,6 @@ import { OptionManager } from './OptionManager';
import { AutomationTriggerState } from 'types/automations/triggers';
import InputText from 'components/Inputs/InputText';
import { InputEntity } from 'components/Inputs/InputTextBubble';
import InputNumber from 'components/Inputs/InputNumber';
import InputTextArea from 'components/Inputs/InputTextArea';
import InputTime from 'components/Inputs/InputTime';
@@ -1,9 +1,6 @@
import { OptionManager } from './OptionManager';
import { AutomationTriggerTemplate } from 'types/automations/triggers';
import InputText from 'components/Inputs/InputText';
import { InputEntity } from 'components/Inputs/InputTextBubble';
import InputNumber from 'components/Inputs/InputNumber';
import InputTextArea from 'components/Inputs/InputTextArea';
import InputTime from 'components/Inputs/InputTime';
@@ -1,10 +1,6 @@
import { OptionManager } from './OptionManager';
import { AutomationTriggerTimePattern } from 'types/automations/triggers';
import InputText from 'components/Inputs/InputText';
import { InputEntity } from 'components/Inputs/InputTextBubble';
import InputNumber from 'components/Inputs/InputNumber';
import InputTextArea from 'components/Inputs/InputTextArea';
import InputTime from 'components/Inputs/InputTime';
export const TriggerTimePattern: OptionManager<AutomationTriggerTimePattern> = {
+2082 -4
View File
File diff suppressed because it is too large. Load diff