UrielCh / proxmox-api

TypeScript Api for proxmox
59 stars 15 forks source link

ReferenceError: AbortController is not defined #15

Closed bogi158 closed 1 year ago

bogi158 commented 1 year ago

Good afternoon,

I am trying to use this library to connect to our Proxmox server, but I get this error here:

Error: FaILED to call GET http://my-node:8006/api2/json/version
    at ProxmoxEngine.doRequest (file:///home/bogi158/Desktop/Workspace/test/ansible/node_modules/proxmox-api/dist/esm/ProxmoxEngine.js:163:27) {
  cause: ReferenceError: AbortController is not defined
      at ProxmoxEngine.doRequest (file:///home/bogi158/Desktop/Workspace/test/ansible/node_modules/proxmox-api/dist/esm/ProxmoxEngine.js:118:32)
router.get("/test", async function (req, res, next) {
  try {
    process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
    const client = Proxmox({
      schema: "http",
      host: process.env.PROXMOX_HOST,
      port: 8006,
      debug: true,
      tokenID: process.env.PROXMOX_USER + "!" + process.env.API_TOKEN_ID,
      tokenSecret: process.env.API_TOKEN_SECRET,
    });
    const version = await client.version.$get();
    res.send(version);
  } catch (e) {
    console.error(e);
    res.status(500).send(e);
  }
});

The error appears during the getVersion call, so the login seems like it is working, but the actual API calls do not. I think the problem is that I am connecting to a https endpoint but the certificates are self-signed and it is giving an error. The login works in curl if I skip ssl verification. Unfortunately the dev environment have only self-signed certificates so I need to be able to skip the ssl verification. Is it possible? I am using process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; but seems like it is not working.

bogi158 commented 1 year ago

Seems like Node 14 is not actually supported. I need to use Node 16 where AbortController is defined. Now it works.

UrielCh commented 1 year ago

I like to have small packages, so the current version uses nodeJS build In fetch, that keeps the module size tiny