diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index ffa9eef72..794d3aa97 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -3,24 +3,52 @@ import { APIObjectType, sendAllProps } from "../../types/api/index"; import axios, { AxiosResponse } from "axios"; import { FlowType } from "../../types/flow"; +// when serving with static files +// We need to add /api/v1/ to the url in the axios calls + +/** + * Retrieves all data from the API. + * @returns {Promise>} A promise that resolves to an AxiosResponse object containing the API data. + */ export async function getAll(): Promise> { - return await axios.get(`/all`); + return await axios.get(`/api/v1/all`); } export async function sendAll(data: sendAllProps) { - return await axios.post(`/predict`, data); + return await axios.post(`/api/v1/predict`, data); } -export async function checkCode( +export async function postValidateCode( code: string ): Promise> { - return await axios.post("/validate/code", { code }); + return await axios.post("/api/v1/validate/code", { code }); +} + +export async function postValidateNode( + nodeId: string, + data: any +): Promise> { + return await axios.post(`/api/v1/validate/node/${nodeId}`, { data }); } export async function checkPrompt( template: string ): Promise> { - return await axios.post("/validate/prompt", { template }); + return await axios.post("/api/v1/validate/prompt", { template }); +} + +/** + * Retrieves the version of the API. + * @returns {Promise>} A promise that resolves to an AxiosResponse object containing the API version. + * @example + * const response = await getVersion(); + * console.log(response.data.version); + * // 0.1.0 + */ +export async function getVersion(): Promise< + AxiosResponse<{ version: string }> +> { + return await axios.get("/api/v1/version"); } export async function getExamples(): Promise { diff --git a/src/frontend/vite.config.ts b/src/frontend/vite.config.ts index b1e7bdd66..6917ecc28 100644 --- a/src/frontend/vite.config.ts +++ b/src/frontend/vite.config.ts @@ -2,11 +2,11 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; import svgr from "vite-plugin-svgr"; const apiRoutes = [ - "/all", - "/predict", - "^/validate/*", - "^/chat/*", - "/version", + "/api/v1/all", + "/api/v1/predict", + "/api/v1/validate/*", + "/api/v1/chat/*", + "/api/v1/version", "/health", ]; @@ -19,7 +19,7 @@ const proxyTargets = apiRoutes.reduce((proxyObj, route) => { changeOrigin: true, secure: false, ws: true, - rewrite: (path) => `/api/v1${path}`, + // rewrite: (path) => `/api/v1${path}`, }; return proxyObj; }, {});