- clean up
- origins
This commit is contained in:
1 parent
f6af594a8f
commit
5e345d20e5
8 files changed
+2103
-20
No files matched your search
+9
-1
@@ -1,7 +1,8 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from src.automations.manager import AutomationManager
|
from src.automations.manager import AutomationManager
|
||||||
from src.env import ROOT_FOLDER
|
from src.env import ROOT_FOLDER, ORIGIN
|
||||||
from .routes import ping, automations
|
from .routes import ping, automations
|
||||||
|
|
||||||
|
|
||||||
@@ -18,6 +19,13 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI:
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print("WARN: could not find web folder")
|
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(ping.router, prefix="/ping")
|
||||||
app.include_router(automations.make_automation_router(automation_mgr), prefix="/automations")
|
app.include_router(automations.make_automation_router(automation_mgr), prefix="/automations")
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
from decouple import config
|
from email.policy import default
|
||||||
|
from decouple import config, Csv
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
ROOT_FOLDER = Path(__file__).parent.parent.absolute()
|
ROOT_FOLDER = Path(__file__).parent.parent.absolute()
|
||||||
BUILD_VERSION = config("BUILD_VERSION", "0.0.0")
|
BUILD_VERSION = config("BUILD_VERSION", "0.0.0")
|
||||||
LOG_LEVEL = config("LOG_LEVEL", "INFO")
|
LOG_LEVEL = config("LOG_LEVEL", "INFO")
|
||||||
|
ORIGIN = config("ORIGIN", cast=Csv(), default="*")
|
||||||
@@ -8,17 +8,18 @@ export const useAPIService = (
|
|||||||
) => {
|
) => {
|
||||||
// state
|
// state
|
||||||
const [state, setState] = useDefaultApiState();
|
const [state, setState] = useDefaultApiState();
|
||||||
const {reload, wrapCall} = makeReloadAutomations(automationAPI, state, setState);
|
const { reload, wrapCall } = makeReloadAutomations(automationAPI, state, setState);
|
||||||
|
|
||||||
|
|
||||||
// initial load of autos
|
// initial load of autos
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
reload();
|
reload();
|
||||||
|
// eslint-disable-next-line
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
state,
|
state,
|
||||||
removeAutomation: wrapCall(automationAPI.remove),
|
removeAutomation: wrapCall(automationAPI.remove),
|
||||||
updateAutomation: wrapCall(automationAPI.update),
|
updateAutomation: wrapCall(automationAPI.update),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,13 +2,16 @@ import { AutomationData } from 'types/automations';
|
|||||||
import { makeAutomationAPI } from './automations';
|
import { makeAutomationAPI } from './automations';
|
||||||
import { makeRemoteAPI } from "./base";
|
import { makeRemoteAPI } from "./base";
|
||||||
import { useAPIService } from './core';
|
import { useAPIService } from './core';
|
||||||
import {useMockAPI} from "./mock";
|
import { useMockAPI } from "./mock";
|
||||||
|
|
||||||
const locationPrefixWeb = window.location.pathname.match(/(.+)\/web/i);
|
const locationPrefixWeb = window.location.pathname.match(/(.+)\/web/i);
|
||||||
|
console.log(process.env)
|
||||||
|
|
||||||
export const useConnectedApiService = () => useAPIService(
|
export const useConnectedApiService = () => useAPIService(
|
||||||
makeAutomationAPI(makeRemoteAPI(
|
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(
|
export const useMockApiService = (initialAutos: AutomationData[]) => useAPIService(
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ import { OptionManager } from './OptionManager';
|
|||||||
import { AutomationTriggerState } from 'types/automations/triggers';
|
import { AutomationTriggerState } from 'types/automations/triggers';
|
||||||
import InputText from 'components/Inputs/InputText';
|
import InputText from 'components/Inputs/InputText';
|
||||||
import { InputEntity } from 'components/Inputs/InputTextBubble';
|
import { InputEntity } from 'components/Inputs/InputTextBubble';
|
||||||
import InputNumber from 'components/Inputs/InputNumber';
|
|
||||||
import InputTextArea from 'components/Inputs/InputTextArea';
|
|
||||||
import InputTime from 'components/Inputs/InputTime';
|
import InputTime from 'components/Inputs/InputTime';
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { OptionManager } from './OptionManager';
|
import { OptionManager } from './OptionManager';
|
||||||
import { AutomationTriggerTemplate } from 'types/automations/triggers';
|
import { AutomationTriggerTemplate } from 'types/automations/triggers';
|
||||||
import InputText from 'components/Inputs/InputText';
|
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';
|
import InputTime from 'components/Inputs/InputTime';
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
import { OptionManager } from './OptionManager';
|
import { OptionManager } from './OptionManager';
|
||||||
import { AutomationTriggerTimePattern } from 'types/automations/triggers';
|
import { AutomationTriggerTimePattern } from 'types/automations/triggers';
|
||||||
import InputText from 'components/Inputs/InputText';
|
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> = {
|
export const TriggerTimePattern: OptionManager<AutomationTriggerTimePattern> = {
|
||||||
|
|||||||
+2082
-4
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user