Configuring ComposeClient with a ceramic URL string that contains a prefix

I’m curious whether it’s possible to configure an instance of ComposeClient from the @composedb/client library to use a ceramic URL string param that contains a URL prefix after the hostname. For example:

const composeClient = new ComposeClient({
  ceramic: 'https://mydomain.io/ceramic',
  definition,
});

Given this configuration, I’d then expect ComposeClient to splice the URLs for its API requests relative to this full URL value rather than just the hostname portion. Eg. POST https://mydomain.io/ceramic/api/v0/multiqueries
In my experience ComposeClient only takes the hostname portion of the ceramic param given (https://mydomain.io in my example)
The ability to configure API clients in this way this is essential to anyone who is hosting their web stack behind a reverse proxy and needs to route HTTP requests to various backend services based on the URL path.

Hello @vkuts ! Thanks for the forum post.

I think I understand the positioning here and what you’re trying to achieve. However, before diving any further, wanted to ask how you’ve gone about testing your expectations (that the hostname portion is parsed from the full URL vs. ComposeClient instances accepting and reading a URL in its entirety)? The reason I ask is that I’ve (briefly) gone through the client libraries and checked with some team members, and it sounds like what you’ve described would be a bug (if it is indeed the case), though I have not yet tested it on my end. There may be something I overlooked, so figured it would be more efficient to check with you first

Hey, no problem, happy to elaborate. So I’ve literally ran an experiment similar to the sample code I’ve provided to create a ComposeClient instance, and then used it to run basic queries, such as looking up a document by streamId. In the network tab I’ve observed the URLs of the query requests that my ComposeClient instance produced, and it was consistently stripping off everything after the hostname, then adding its own api/v0/multiqueries bit.
I’ve also looked at your code, and I can see why it’s behaving the way it does in ceramic-http-client.js constructor: https://github.com/ceramicnetwork/js-ceramic/blob/18bb1ce3c61bd05a697099d70d367b3b9df0a80d/packages/http-client/src/ceramic-http-client.ts#L81C1-L81C1
The behaviour of new URI(url, base) is to replace the entire relative URL part of base after the hostname with the new relative URL given (url). See URL: URL() constructor - Web APIs | MDN

@vkuts thank you - this is exactly what I was looking for.

I’d like to loop in @spencer and @ukstv on this thread from the 3Box side.

Also @vkuts - would the following be an accurate brief summary of the need:

Say you have an application hosted on https://example.com - the idea is that you’d want the ability to serve your node endpoint on an extension of the same host (for example, https://example.com/ceramic).

Thanks again!

Yes exactly right @mzk . I want to be able to query my Ceramic node’s API at https://example.com/ceramic as opposed to https://example.com:7007 or some other dedicated port.

Thanks for letting us know about this issue! I have filed a ticket for the development team to fix this bug.

1 Like

@vkuts just keeping you in the loop: Patch for http-client URL constructor by mzkrasner · Pull Request #3012 · ceramicnetwork/js-ceramic · GitHub

Will let you know once it’s merged

@vkuts this has been merged: Patch for http-client URL constructor by mzkrasner · Pull Request #3012 · ceramicnetwork/js-ceramic · GitHub

In terms of timing between now and full release, i’d anticipate between 1-2 weeks