fix: fetch was not using rest requests
This commit is contained in:
+5
-1
@@ -1,5 +1,6 @@
|
|||||||
from fastapi import FastAPI, Depends, HTTPException, status
|
from fastapi import FastAPI, Depends, HTTPException, status
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
from fastapi.middleware.trustedhost import TrustedHostMiddleware
|
||||||
from fastapi.security import OAuth2PasswordRequestForm
|
from fastapi.security import OAuth2PasswordRequestForm
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
@@ -10,8 +11,11 @@ from .database import SessionLocal, engine, Base
|
|||||||
|
|
||||||
Base.metadata.create_all(bind=engine)
|
Base.metadata.create_all(bind=engine)
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI(proxy_headers=True)
|
||||||
|
|
||||||
|
app.add_middleware(
|
||||||
|
TrustedHostMiddleware, allowed_hosts=["site-api.muszyn.dev", "*.muszyn.dev"]
|
||||||
|
)
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=[
|
allow_origins=[
|
||||||
|
|||||||
@@ -83,7 +83,12 @@ function BlogPage() {
|
|||||||
const [blogs, setBlogs] = useState<Blog[]>([]);
|
const [blogs, setBlogs] = useState<Blog[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`${API_URL}/blogs`)
|
fetch(`${API_URL}/blogs`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
})
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((data: Blog[]) => setBlogs(data))
|
.then((data: Blog[]) => setBlogs(data))
|
||||||
.catch((err) => console.error(err));
|
.catch((err) => console.error(err));
|
||||||
|
|||||||
@@ -4,7 +4,12 @@ import { API_URL } from "./constants";
|
|||||||
export function BlogList() {
|
export function BlogList() {
|
||||||
const [content, setContent] = useState("");
|
const [content, setContent] = useState("");
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`${API_URL}/get-blogs`)
|
fetch(`${API_URL}/get-blogs`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
})
|
||||||
.then((res) => res.text())
|
.then((res) => res.text())
|
||||||
.then(setContent);
|
.then(setContent);
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
@@ -16,7 +16,12 @@ export function BlogViewer() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!slug) return;
|
if (!slug) return;
|
||||||
fetch(`${API_URL}/blogs/${slug}`)
|
fetch(`${API_URL}/blogs/${slug}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
})
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((data: Blog) => setBlog(data))
|
.then((data: Blog) => setBlog(data))
|
||||||
.catch((err) => console.error(err));
|
.catch((err) => console.error(err));
|
||||||
|
|||||||
@@ -16,7 +16,12 @@ export function EditBlog() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!slug) return;
|
if (!slug) return;
|
||||||
fetch(`${API_URL}/blogs/${slug}`)
|
fetch(`${API_URL}/blogs/${slug}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
})
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((data: Blog) => {
|
.then((data: Blog) => {
|
||||||
setBlog(data);
|
setBlog(data);
|
||||||
|
|||||||
Reference in New Issue
Block a user