disease-sh/node-api

NovelCovid 2.1.1

interpegasus opened this issue · 3 comments

Thanks for a great library!

Currently my app has been using Version 1 via react JS

However Version 2 of NovelCovid does not seem to work.

Documentation: https://www.npmjs.com/package/novelcovid

Eg:

    const api = require("novelcovid");

    // you can choose which URL to use, this will not change the behaviour of the API
    api.settings({
      baseUrl: "https://disease.sh" | "https://api.caw.sh" | "https://corona.lmao.ninja",
    });
    debugger;
    // Any call to api() triggers an error
    api.all().then(console.log);

Error

CentraRequest.js:13 Uncaught TypeError: URL is not a constructor
    at new CentraRequest (CentraRequest.js:13)
    at push../node_modules/@aero/centra/createRequest.js.module.exports (createRequest.js:3)
    at fetchJson (index.js:3)
    at Object.countries (index.js:54)
    at eval (eval at UiContainer._this.setCountryData (UiContainer.js:119), <anonymous>:1:5)
    at UiContainer._this.setCountryData (UiContainer.js:119)
    at UiContainer.componentDidMount (UiContainer.js:171)
    at commitLifeCycles (react-dom.development.js:19814)
    at commitLayoutEffects (react-dom.development.js:22803)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
    at invokeGuardedCallback (react-dom.development.js:292)
    at commitRootImpl (react-dom.development.js:22541)
    at unstable_runWithPriority (scheduler.development.js:653)
    at runWithPriority$1 (react-dom.development.js:11039)
    at commitRoot (react-dom.development.js:22381)
    at finishSyncRender (react-dom.development.js:21807)
    at performSyncWorkOnRoot (react-dom.development.js:21793)
    at scheduleUpdateOnFiber (react-dom.development.js:21188)
    at updateContainer (react-dom.development.js:24373)
    at react-dom.development.js:24758
    at unbatchedUpdates (react-dom.development.js:21903)
    at legacyRenderSubtreeIntoContainer (react-dom.development.js:24757)
    at render (react-dom.development.js:24840)
    at Module../src/index.js (index.js:12)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object.1 (serviceWorker.js:141)
    at __webpack_require__ (bootstrap:784)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1

Thanks in advance

pujux commented

documentation != code you can copy and paste

by this, what is meant is that you can specify one of those 3 urls (the line being an OR operator)

api.settings({
      baseUrl: "https://disease.sh" | "https://api.caw.sh" | "https://corona.lmao.ninja",
});

you can leave that part out completely though as it is optional to specify a different domain to the API

Hi @puf17640 Thanks for the clarification and quick reply.

I retested again leaving that portion out and setting only one URL, but the issue remains.

      const api = require("novelcovid");

       // you can choose which URL to use, this will not change the behaviour of the API
       api.settings({
           baseUrl: "https://disease.sh",
       });
       debugger;
       // Any call to api() triggers an error
       api.all().then(console.log);

The issue seems to be caused by the node module @aero/centra/createRequest.js

Perhaps it can be fixed by setting a specific version of that package that works on your end?

Thanks in advance

Test Result

     const api = require("novelcovid")
      debugger;
      // Any call to api() triggers an error
      api.all().then(console.log);

Result
Screen Shot 2020-05-29 at 3 06 03 PM
@puf17640