Summary of responses and how to handle them:
The response will come back with a boolean key ok
. If the response has a successful status, ex: 200
, then it will be true
, else it will be false
. A payload is located in the responses body
. For JSON data, it can be consumed using JSON.stringify()
or await response.json()
.
The response will have a boolean ok
key, but the body
might not contain the expect data, which will cause an error that will be caught in the catch
clause.
Maybe because you are offline or becauses the server is unreachable, sometimes the request will fail because of the front. In that case, no response
is returned and an error
is immediately caught in the catch
clause.
You need to install NodeJS: https://github.com/nvm-sh/nvm
You also need Caddy installed: https://caddyserver.com/v2
Run npm run dev:server
to start the Node server on port 5000
.
Run npm run dev:caddy
to start the server that will serve the front on port 8080
and proxy the Node server on localhost:8080/api
. The proxying helps prevent CORS issues.
Run npm start
to start the production setup.