Unleash / unleash-proxy-client-js

A browser client that can be used together with the unleash-proxy.
Apache License 2.0
47 stars 46 forks source link

Metrics implementation adds a trailing slash to app url #191

Closed tomascenteno42 closed 9 months ago

tomascenteno42 commented 9 months ago

Describe the bug

On the metrics class constructor the url is being parsed to a URL if its not an instance of the URL JS class. If you instantiate a url without the base param it will append a slash (/) to the end of the URI. The problem with this is that on the sendMetrics method of the Metrics class you append a slash (/) followed by /client/metrics to the end of the initialized url const url = `${this.url}/client/metrics`;

Steps to reproduce the bug

Start the unleash client with an app url as a string:

export const config: IFlagProvider['config'] = { url: 'https://my-unleash-endpoint', clientKey: UNLEASH_CLIENT_KEY, appName: UNLEASH_APP_NAME, refreshInterval: Number(UNLEASH_REFRESH_INTERVAL), metricsInterval: Number(UNLEASH_METRICS_INTERVAL), storageProvider: { save: (name: string, data: DataUnleash | unknown) => AsyncStorage.setItem(name, JSON.stringify(data)), get: async (name: string) => { const data = await AsyncStorage.getItem(name); return data ? JSON.parse(data) : undefined; }, }, };

And check the interaction with the metrics url. You should see this url: https://my-unleash-endpoint//client/metrics

Expected behavior

Metrics url should have a valid URL format when adding /client/metrics.

Logs, error output, etc.

No response

Screenshots

No response

Additional context

No response

Unleash version

^2.5.0

Subscription type

None

Hosting type

None

SDK information (language and version)

No response

Tymek commented 9 months ago

I couldn't reproduce this issue. Are you sure your package version and Unleash are up-to-date?

tomascenteno42 commented 9 months ago

Hey! Upon further inspection. I've checked this case for node, on different versions and it's not adding the trailing slash. I believe the problem is coming from my project's react native version ("^0.67.3").

"react-native": "^0.67.3"
"@unleash/proxy-client-react": "^3.6.0"

I use "node": "16.19.0" to build the project.

Tymek commented 9 months ago

I'm glad to hear that. I'll close this issue for now. Please reopen it if there is anything we can patch