diff --git a/inventory-manager/src/services/Requests.ts b/inventory-manager/src/services/Requests.ts index 99ce6d2..70bf27e 100644 --- a/inventory-manager/src/services/Requests.ts +++ b/inventory-manager/src/services/Requests.ts @@ -1,8 +1,6 @@ import axios, {type AxiosResponse} from "axios"; import type {Product, ProductResponse} from "../types/Product"; -const BASE_URL = "http://localhost:9090"; - export const getProducts = async (filters?: { name?: string; category?: string[]; @@ -15,18 +13,18 @@ export const getProducts = async (filters?: { sortBy?: string; sortDir?: "asc" | "desc"; }): Promise => { - const response = await axios.get(`${BASE_URL}/products`, { + const response = await axios.get(`/api/products`, { params: filters, }); return response.data; }; export const getCategories = async (): Promise> => { - return await axios.get(`${BASE_URL}/products/categories`); + return await axios.get(`/api/products/categories`); }; export const getSummary = async (): Promise> => { - return await axios.get(`${BASE_URL}/products/summary`); + return await axios.get(`/api/products/summary`); }; export const getFilteredProducts = async (params?: { @@ -42,7 +40,7 @@ export const getFilteredProducts = async (params?: { sortBy?: string; sortDir?: "asc" | "desc"; }): Promise> => { - return await axios.get(`${BASE_URL}/products/filters`, { + return await axios.get(`/api/products/filters`, { params, paramsSerializer: (params) => { const query = new URLSearchParams(); @@ -59,23 +57,23 @@ export const getFilteredProducts = async (params?: { }; export const createProduct = async (product: Omit): Promise => { - const response = await axios.post(`${BASE_URL}/products`, product); + const response = await axios.post(`/api/products`, product); return response.data; }; export const updateProduct = async (id: string, product: Partial): Promise => { - const response = await axios.put(`${BASE_URL}/products/${id}`, product); + const response = await axios.put(`/api/products/${id}`, product); return response.data; }; export const markOutOfStock = async (id: string): Promise => { - await axios.patch(`${BASE_URL}/products/${id}/outofstock`); + await axios.patch(`/api/products/${id}/outofstock`); }; export const markInStock = async (id: string): Promise => { - await axios.patch(`${BASE_URL}/products/${id}/instock`); + await axios.patch(`/api/products/${id}/instock`); }; export const deleteProduct = async (id: string): Promise => { - await axios.delete(`${BASE_URL}/products/${id}`); + await axios.delete(`/api/products/${id}`); }; diff --git a/inventory-manager/vite.config.ts b/inventory-manager/vite.config.ts index 8b0f57b..4217b13 100644 --- a/inventory-manager/vite.config.ts +++ b/inventory-manager/vite.config.ts @@ -1,7 +1,19 @@ +/// import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' // https://vite.dev/config/ export default defineConfig({ plugins: [react()], -}) + server: { + host: true, + port: 8080, + proxy: { + '/api': { + target: 'http://localhost:9090', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, ''), + }, + }, + }, +}) \ No newline at end of file