woocommerce / woocommerce-rest-api-js-lib

New JavaScript library for WooCommerce REST API
https://www.npmjs.com/package/@woocommerce/woocommerce-rest-api
MIT License
273 stars 76 forks source link

Set parse URL independent of browser window #92

Open LeorentKelmendi opened 3 years ago

LeorentKelmendi commented 3 years ago

Based on parse-url plugin:

Note that when url-parse is used in a browser environment, it will default to using the browser's current window location as the base URL when parsing all inputs. To parse an input independently of the browser's current URL (e.g. for functionality parity with the library in a Node environment), pass an empty location object as the second parameter:

var parse = require('url-parse');
parse('hostname', {});

when i tried to use the plugin with gatsby SSR failed due to url not being string as it could not extract window info causing Cannot read property 'split' of null to crash whole SSR.

passing second argument as {} solved the issue in SSR.