setup local hosting

This commit is contained in:
ari committed 2022-01-04 23:27:23 -05:00
1 parent 25e65540e1
commit 63cfd936b5
9 files changed
+31 -22

No files matched your search

-1
View File
@@ -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}) {
+14 -7
View File
@@ -1,4 +1,4 @@
import { APIRequest, APIResponse } from "./types";
import { APIRequest, APIResponse } from './types';
export interface API {
makeCall: <Res = any, Req = any>(req: APIRequest<Req>) => Promise<APIResponse<Res>>;
@@ -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<any>;
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
}
})
+1 -1
View File
@@ -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))
+2 -2
View File
@@ -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;