POST http://localhost:3000/createUser 500 (Internal Server Error)

244 Views Asked by At

The server works perfectly fine in POSTMAN but will not work in the browser and gives a 500 Internal Server Error when creating a new user. I double check my backend and everything is as it should be.

These are the error in my console log

  1. Login.js:31 POST http://localhost:3000/createUser 500 (Internal Server Error)
  • 31 fetch('/createUser', options)
  1. Login.js:44 SyntaxError: Unexpected token 'P', "Proxy erro"... is not valid JSON
  • 44 console.log(error);

  • This was also in the console response

: Proxy error: Could not proxy request /createUser from localhost:3000 to http://localhost:1299/ (HPE_CR_EXPECTED).

This is the error in my server log

  1. Proxy error: Could not proxy request /createUser from localhost:3000 to http://localhost:1299/

Here is the full block of code:

function register() {
        setMessage('');
        const userDto = {
            userName: userName,
            password: password,
       };
31      console.log(userDto);
        const options = {
            method: 'POST',
            body: JSON.stringify(userDto)
        };
        fetch('/createUser', options)
            .then((res) => res.json())
            .then((apiRes) => {
                console.log(apiRes);
                if (apiRes.status) {
                    setUserName('');
                    setPassword('');
                    setMessage('Your account has been created!');
                } else {
                    setMessage(apiRes.message);
                }
            })
            .catch((error) => {
44              console.log(error);
                setMessage('User was not created, SERVER ERROR');
            });
    }

I have tried:

  • Changing my proxy in package.json
  • Changing header to 'Content-Type': 'application/json'
  • Double checking to correct JSON
  • Clearing my browser and cache
  • Double checking back-end server for mistakes
0

There are 0 best solutions below