diff --git a/README.md b/README.md index 1004720..102c933 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,6 @@ Members: ## Dev build instructions -To connect to backend in dev mode edit `API_URL` to `localhost:8000` in `front/src/config.js` - Frontend: ```sh diff --git a/back/main.py b/back/main.py index 1dcf902..34cb222 100644 --- a/back/main.py +++ b/back/main.py @@ -5,7 +5,6 @@ from fastapi.staticfiles import StaticFiles from fastapi.security import OAuth2PasswordRequestForm, OAuth2PasswordBearer from fastapi.templating import Jinja2Templates from fastapi.requests import Request -from fastapi.middleware.cors import CORSMiddleware from pydantic import json @@ -33,15 +32,6 @@ db = SessionLocal() app = FastAPI() -# CORS fix for development -app.add_middleware( - CORSMiddleware, - allow_origins=["http://localhost:5173", "http://localhost:8000"], - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], -) - templates = Jinja2Templates(directory="./front/dist") app.mount("/static", StaticFiles(directory = "./front/dist")) diff --git a/front/public/watermelon.mp4 b/front/public/watermelon.mp4 deleted file mode 100644 index 21efaf3..0000000 Binary files a/front/public/watermelon.mp4 and /dev/null differ diff --git a/front/src/hooks/api/useFetch.js b/front/src/hooks/api/useFetch.js index 5422f82..a6c67e5 100644 --- a/front/src/hooks/api/useFetch.js +++ b/front/src/hooks/api/useFetch.js @@ -10,13 +10,10 @@ const useFetch = (url, params, initialData) => { .then(res => { if (!res.ok) { switch (res.status) { - case 401: { + case 401: throw new Error("Ошибка авторизации") - } - case 404: { - new Error("Объект не найден") - } - break + case 404: + throw new Error("Объект не найден") default: { throw new Error("Ошибка ответа от сервера") } @@ -32,6 +29,10 @@ const useFetch = (url, params, initialData) => { .catch(err => { setError("Ошибка сети") setLoading(false) + + if (import.meta.env.DEV) { + console.log(url, params, err) + } }) }, [url, params]) diff --git a/front/vite.config.js b/front/vite.config.js index bf855e6..4e720be 100644 --- a/front/vite.config.js +++ b/front/vite.config.js @@ -1,10 +1,19 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +const BACK_ADDRESS = 'http://127.0.0.1:8000' + // https://vitejs.dev/config/ export default defineConfig( ({ command }) => ({ base: (command === 'serve') ? "/" : "/static", plugins: [react()], + server: { + proxy: { + '/api': BACK_ADDRESS, + '/static': BACK_ADDRESS, + '/uploads': BACK_ADDRESS + } + } }) )