janhommes / o.js

o.js - client side oData lib.
https://janhommes.github.io/o.js/example/
MIT License
238 stars 57 forks source link

Invalid referrer #155

Closed brainboutique closed 12 months ago

brainboutique commented 1 year ago

Option "referrer" is defaulting to "client" - which is not a valid URL. Therefore if "referrer" is not set manually via Options object, any request fails with:

>  Error running OData query TypeError: Referrer "client" is not a valid URL.
>      at new Request (node:internal/deps/undici/undici:7062:21)
>      at ORequest.get (F:\A\A\functions\node_modules\odata\dist\cjs\o.js:80:23)
>      ... 4 lines matching cause stack trace ...
>      at new Promise (<anonymous>)
>      at __awaiter (F:\A\A\functions\node_modules\odata\dist\cjs\o.js:32:12)
>      at OHandler.getFetch (F:\A\A\functions\node_modules\odata\dist\cjs\o.js:540:16)
>      at OHandler.<anonymous> (F:\A\A\functions\node_modules\odata\dist\cjs\o.js:336:51) {
>    [cause]: TypeError [ERR_INVALID_URL]: Invalid URL
>        at new NodeError (node:internal/errors:399:5)
>        at URL.onParseError (node:internal/url:565:9)
>        at new URL (node:internal/url:645:5)
>        at new Request (node:internal/deps/undici/undici:7060:32)
>        at ORequest.get (F:\A\A\functions\node_modules\odata\dist\cjs\o.js:80:23)
>        at OHandler.<anonymous> (F:\A\A\functions\node_modules\odata\dist\cjs\o.js:564:63)
>        at step (F:\A\A\functions\node_modules\odata\dist\cjs\o.js:62:23)
>        at Object.next (F:\A\A\functions\node_modules\odata\dist\cjs\o.js:43:53)
>        at F:\A\A\functions\node_modules\odata\dist\cjs\o.js:36:71
>        at new Promise (<anonymous>) {
>      input: 'client',
>      code: 'ERR_INVALID_URL'

Workaround: Use

o(config.url, {
        headers: {
....
        },
        referrer:undefined
      })
janhommes commented 1 year ago

Yes we set the header here: https://github.com/janhommes/o.js/blob/334e0782d81cb259917954048206d260c77e35f8/src/o.ts#L85

Don't exactly remember why I did that. To fix this, we should test if we can remove it.