Answer the question
In order to leave comments, you need to log in
Error 500 when proxying requests - how to solve?
"Proxy error: Could not proxy request /api/auth/register from localhost:3000 to localhost:5000/. "
package.json on the client -
on the backend I run through"proxy": "http://localhost:5000/",
"dev": "concurrently \"npm run server\" \"npm run client\""
Proxy error: Could not proxy request /api/auth/register from localhost:3000 to http://localhost:5000/. [1] See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
http.hook.js:15 POST http://localhost:3000/api/auth/register 500 (Internal Server Error)
Request Payload:
{email: "[email protected]", password: "dfgdgdhg"} email: "[email protected]" password: "dfgdgdhg"
Request URL: http://localhost:3000/api/auth/register Request Method: POST Status Code: 500 Internal Server Error Remote Address: 127.0.0.1:3000 Referrer Policy: no-referrer-when-downgrade
Proxy error: Could not proxy request /api/auth/register from localhost:3000 to http://localhost:5000/ (ECONNREFUSED).
import {useState, useCallback} from 'react'
export const useHttp = () => {
const [loading, setLoading] = useState(false)
const [error, setError] = useState(null)
const request = useCallback(async (url, method = 'GET', body = null, headers = {}) => {
setLoading(true)
try {
if (body) {
body = JSON.stringify(body)
headers['Content-Type'] = 'application/json'
}
const response = await fetch(url, {method, body, headers})
const data = await response.json()
if (!response.ok) {
throw new Error(data.message || 'Что-то пошло не так')
}
setLoading(false)
return data
} catch (e) {
setLoading(false)
setError(e.message)
throw e
}
}, [])
const clearError = useCallback(() => setError(null), [])
return { loading, request, error, clearError }
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question