"Proxy error: Could not proxy request /api/auth/register from localhost:3000 to
localhost:5000/."
package.json на клиенте -
"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).
В браузере сообщение - "unexpected token p in json at position 0"
В консоли:
http.hook.js:15 POST http://localhost:3000/api/auth/register 500 (Internal Server Error)
Request Payload:
{email: "dhsdh@mail.ru", password: "dfgdgdhg"} email: "dhsdh@mail.ru" 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).
http.hook.js
spoilerimport {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 }
}