From bf73ed1698eb02b6da04f4fc05d92cd3df614f55 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 6 Dec 2024 03:25:50 +0100 Subject: [PATCH] api proxy working :) --- front/src/components/ArticlesSection.tsx | 2 +- front/vite.config.ts | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/front/src/components/ArticlesSection.tsx b/front/src/components/ArticlesSection.tsx index fe52486..a7b5df2 100644 --- a/front/src/components/ArticlesSection.tsx +++ b/front/src/components/ArticlesSection.tsx @@ -9,7 +9,7 @@ export default function ArticlesSection() { const [error, setError] = useState(null); useEffect(() => { - fetch('/api/article') + fetch('/api/articles') .then(response => response.json()) .then((data: ArticlePreview[]) => setArticlePreviews(data)) .catch(_ => setError('Failed to fetch articles')) diff --git a/front/vite.config.ts b/front/vite.config.ts index 9e06ec4..795d340 100644 --- a/front/vite.config.ts +++ b/front/vite.config.ts @@ -7,10 +7,25 @@ export default defineConfig({ server: { proxy: { '/api': { - target: 'http://localhost:2486', + target: 'http://127.0.0.1:2486', changeOrigin: true, - rewrite: path => path.replace(/^\/api/, '') + secure: false, + ws: true, + /* + configure: (proxy, _options) => { + proxy.on('error', (err, _req, _res) => { + console.log('proxy error', err); + }); + proxy.on('proxyReq', (proxyReq, req, _res) => { + console.log('Sending Request to the Target:', req.method, req.url); + }); + proxy.on('proxyRes', (proxyRes, req, _res) => { + console.log('Received Response from the Target:', proxyRes.statusCode, req.url); + }); + }, + */ + //rewrite: path => path.replace(/^\/api/, '') } } - } + }, })