buttons for direct command sending

smsoousaa year ago

Hello everyone, I'm trying to implement 2 buttons to turn the engine on and off, through the device popup, but I must be missing some detail, because I got the error 404 Not Found. Any idea? Thanks

const [loading, setLoading] = useState(false);

  const handleBlockMotor = async () => {
    setLoading(true);
    try {
      await axios.post('/api/command/send', {
        type: 'engineStop',
        attributes: {},
        deviceId: 14,
      });
    } catch (error) {
      error(error);
    } finally {
      setLoading(false);
    }
  };

  const handleUnblockMotor = async () => {
    setLoading(true);
    try {
      await axios.post('/api/command/send', {
        type: 'engineResume',
        attributes: {},
        deviceId: 14,
      });
    } catch (error) {
      error(error);
    } finally {
      setLoading(false);
    }
  };
.
.
.
<div>
<Button onClick={handleBlockMotor} disabled={loading}>
Block Motor
</Button>
<Button onClick={handleUnblockMotor} disabled={loading}>
Unblock Motor
</Button>
</div>

console data:

URL da Solicitação: http://localhost:3000/api/command/send
Método de solicitação: POST
Código do status: 404 Not Found
Endereço Remoto: 127.0.0.1:3000
Política do Referenciador: strict-origin-when-cross-origin
access-control-allow-credentials: true
access-control-allow-headers: origin, content-type, accept, authorization
access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS
access-control-allow-origin: http://localhost:3000
connection: close
content-length: 44
date: Sun, 05 Feb 2023 03:23:06 GMT
server: Jetty(10.0.12)
X-Powered-By: Express
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: pt-BR,pt;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
Connection: keep-alive
Content-Length: 51
Content-Type: application/json
Cookie: JSESSIONID=node0fh90jx5t876f12upodlv22fxs628.node0
Host: localhost:3000
Origin: http://localhost:3000
Referer: http://localhost:3000/
sec-ch-ua: "Not_A Brand";v="99", "Microsoft Edge";v="109", "Chromium";v="109"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.78

{type: "engineStop", attributes: {}, deviceId: 14}
attributes: {}
deviceId: 14
type:  "engineStop"

HTTP 404 Not Found - NotFoundException (...)