Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last url segment is removed from custom global url values #294

Open
lox opened this issue May 21, 2024 · 2 comments
Open

Last url segment is removed from custom global url values #294

lox opened this issue May 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@lox
Copy link
Contributor

lox commented May 21, 2024

What is the current behavior?

The last path segment gets trimmed from custom api endpoint urls.

If setting global: { url: 'https://example.com/test/url/is/long/' }, the url that is fetched for prerecorded transcribe is https://example.com/test/url/is/v1/listen (note the last segment removed).

This was unexpected!

For context, I am building a mock endpoint for our test suites.

Steps to reproduce

import { createClient } from '@deepgram/sdk'
import fs from 'fs'

const client = createClient('nope', {
  global: { url: 'https://example.com/test/url/is/long/' },
  _experimentalCustomFetch: (url, init) => {
    return Response.json({
      url: url.href,
    })
  },
})

const { result, error } = await client.listen.prerecorded.transcribeFile(
  fs.createReadStream('./testdata/polar-bear.webm'),
  {
    model: 'nova',
  }
)

console.log(result)
console.log(error)

Output is:

{
  url: 'https://example.com/test/url/is/v1/listen?model=nova'
}

Expected behavior

I would expect the last segment of the url to be preserved.

Please tell us about your environment

@deepgram/sdk 3.3.2

Other information

Looks like the trailing slash is trimmed in Interested in a PR that preserves the trailing slash here?

return new URL(stripTrailingSlash(url));
.

A hacky workaround is to add a double slash at the end.

@lukeocodes
Copy link
Contributor

Interesting. I expect it is to do with how it is parsed using the URL class in JavaScript

@lukeocodes
Copy link
Contributor

Hmm thinking more about this. We're trying to normalise the URL string for when we add it to the object. Is there a reason you need the trailing slash at all?

@naomi-lgbt naomi-lgbt added the bug Something isn't working label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants