generated from lucien/actix-react-template
api proxy working :)
This commit is contained in:
parent
e53fc84ac3
commit
bf73ed1698
2 changed files with 19 additions and 4 deletions
|
@ -9,7 +9,7 @@ export default function ArticlesSection() {
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch('/api/article')
|
fetch('/api/articles')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then((data: ArticlePreview[]) => setArticlePreviews(data))
|
.then((data: ArticlePreview[]) => setArticlePreviews(data))
|
||||||
.catch(_ => setError('Failed to fetch articles'))
|
.catch(_ => setError('Failed to fetch articles'))
|
||||||
|
|
|
@ -7,10 +7,25 @@ export default defineConfig({
|
||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://localhost:2486',
|
target: 'http://127.0.0.1:2486',
|
||||||
changeOrigin: true,
|
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/, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue