Estoy tratando de actualizar alguna información en mi servidor json, pero parece que todavía no llego a mis puntos finales. ¿Estoy configurando mu urls correctamente? He intentado un par de veces cambiando mi URL. En mi mente pienso que estoy haciendo lo correcto. Pero los mensajes de error me dicen lo contrario. Agradecería cualquier orientación. Gracias por adelantado.
Funciones de componentes
const [author, setAuthor] = useState(""); const [text, setText] = useState(""); useEffect(() => { const loadArticleInfo = async () => { try { const response = await axios.get(`http://localhost:5000/articles/${id}`) setArticleInfo(response.data) } catch (err) { console.log(err); } }; loadArticleInfo(); }, [id]); const addUpvote = async () => { const response = await axios.put(`/articles/${id}/upvotes`, {...articleInfo, upvotes: articleInfo.upvotes + 1, }); const updatedArticle = response.data; setArticleInfo(updatedArticle); }; const addComment = async () => { const temp_comments = [...articleInfo.comments, {author: author, text: text}]; console.log(temp_comments, "New Comment"); const response = await axios.put(`http://localhost:5000/articles/${id}/comments`, {...articleInfo, comments: temp_comments}); console.log(response.data) setArticleInfo({...articleInfo, comments: response.data}); setAuthor(""); setText("");JSON de muestra
{ "articles": [ { "id": "2", "name": "learn-node", "title": "How to Build a Node Server in 10 Minutes", "content": [ "`In this article, ....." ], "upvotes": 9, "comments": [ { "author": "anon", "text": "Node really changed things for me since I no longer have to master PHP... JS all the way!" }, { "author": "Tester", "text": "No!!! Not another server!" }Edité mis direcciones URL para esto
const respuesta = esperar axios.put( /articles/${id}/ , {...articleInfo, upvotes: articleInfo.upvotes + 1, }