From 21440578a78e97a4e766cab0e2b383413d2c39ab Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sun, 11 Jun 2023 12:17:00 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(API):=20add=20/api/v1/=20p?= =?UTF-8?q?refix=20to=20API=20routes=20=E2=9C=A8=20feat(API):=20add=20getV?= =?UTF-8?q?ersion=20function=20to=20retrieve=20the=20version=20of=20the=20?= =?UTF-8?q?API=20The=20API=20routes=20have=20been=20updated=20to=20include?= =?UTF-8?q?=20the=20/api/v1/=20prefix=20to=20improve=20semantics=20and=20a?= =?UTF-8?q?void=20conflicts=20with=20other=20routes.=20The=20getVersion=20?= =?UTF-8?q?function=20has=20been=20added=20to=20retrieve=20the=20version?= =?UTF-8?q?=20of=20the=20API.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/controllers/API/index.ts | 38 ++++++++++++++++++++--- src/frontend/vite.config.ts | 12 +++---- 2 files changed, 39 insertions(+), 11 deletions(-) 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; }, {});