Removed builtin static video file

Switched from CORS to proxy for dev
This commit is contained in:
Dmitriy Shishkov 2023-07-10 17:14:36 +03:00
parent c2ee2f5b02
commit dcd91cb9b4
Signed by: dm1sh
GPG Key ID: 027994B0AA357688
5 changed files with 16 additions and 18 deletions

View File

@ -10,8 +10,6 @@ Members:
## Dev build instructions ## Dev build instructions
To connect to backend in dev mode edit `API_URL` to `localhost:8000` in `front/src/config.js`
Frontend: Frontend:
```sh ```sh

View File

@ -5,7 +5,6 @@ from fastapi.staticfiles import StaticFiles
from fastapi.security import OAuth2PasswordRequestForm, OAuth2PasswordBearer from fastapi.security import OAuth2PasswordRequestForm, OAuth2PasswordBearer
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
from fastapi.requests import Request from fastapi.requests import Request
from fastapi.middleware.cors import CORSMiddleware
from pydantic import json from pydantic import json
@ -33,15 +32,6 @@ db = SessionLocal()
app = FastAPI() 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") templates = Jinja2Templates(directory="./front/dist")
app.mount("/static", StaticFiles(directory = "./front/dist")) app.mount("/static", StaticFiles(directory = "./front/dist"))

Binary file not shown.

View File

@ -10,13 +10,10 @@ const useFetch = (url, params, initialData) => {
.then(res => { .then(res => {
if (!res.ok) { if (!res.ok) {
switch (res.status) { switch (res.status) {
case 401: { case 401:
throw new Error("Ошибка авторизации") throw new Error("Ошибка авторизации")
} case 404:
case 404: { throw new Error("Объект не найден")
new Error("Объект не найден")
}
break
default: { default: {
throw new Error("Ошибка ответа от сервера") throw new Error("Ошибка ответа от сервера")
} }
@ -32,6 +29,10 @@ const useFetch = (url, params, initialData) => {
.catch(err => { .catch(err => {
setError("Ошибка сети") setError("Ошибка сети")
setLoading(false) setLoading(false)
if (import.meta.env.DEV) {
console.log(url, params, err)
}
}) })
}, [url, params]) }, [url, params])

View File

@ -1,10 +1,19 @@
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
const BACK_ADDRESS = 'http://127.0.0.1:8000'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig( export default defineConfig(
({ command }) => ({ ({ command }) => ({
base: (command === 'serve') ? "/" : "/static", base: (command === 'serve') ? "/" : "/static",
plugins: [react()], plugins: [react()],
server: {
proxy: {
'/api': BACK_ADDRESS,
'/static': BACK_ADDRESS,
'/uploads': BACK_ADDRESS
}
}
}) })
) )