codemanas / cm-typesense-docs

Documentation for Typesense Plugin
8 stars 0 forks source link

Configuration should allow hosting typesense being a reverse proxy #6

Open prathamesh-gharat opened 1 year ago

prathamesh-gharat commented 1 year ago

The URL is constructed like {NODE URI}{PORT} which results in. https://example.com/reverse-proxy/:443/health

prathamesh-gharat commented 1 year ago

The following structure will allow more flexibility. {protocol}://{hostname}:{port}{/api_prefix}

digamber89 commented 1 year ago

@prathamesh-gharat the URL is indeed constructed as you have specified. Except for the /api_prefix part. That would be upto developers to add.

prathamesh-gharat commented 1 year ago

Could you please share a screenshot / text guide of how to add the /api_prefix from the WordPress backend screen? or are there any hooks provided by the plugin in WordPress that allows us to do the same?

digamber89 commented 1 year ago

Hi @prathamesh-gharat

I am not seeing your objective here. Can you please provide and example of what you're trying to do.

prathamesh-gharat commented 1 year ago

Oh sorry, I re-read my first message and it was not clear. I was trying to host typesense in a sub-directory like structure. For example https://example.com/reverse-proxy/health but the plugin ends up constructing the URL like following. https://example.com/reverse-proxy/:443/health which is wrong, it should have been https://example.com:443/reverse-proxy/health. The important part of the example is 'reverse-proxy' and ':443'

Edit 1: Which is why I suggest providing an additional field / hook for API prefix i.e. something like/reverse-proxy` in my example.

digamber89 commented 1 year ago

@prathamesh-gharat This isn't possible right now. On the frontend we use instant search js And the configuration with Typesense Adapter is like the following

 const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
            server: {
                apiKey: defaultSettings.search_api_key,// Be sure to use an API key that only allows search operations
                nodes: [{
                    host: defaultSettings.node,
                    port: defaultSettings.port,
                    protocol: protocol,
                }],
            }, cacheSearchResultsForSeconds: 2 * 60, // Cache search results from server. Defaults to 2 minutes. Set to 0 to disable caching.
            // The following parameters are directly passed to Typesense search API endpoint.
            //  So you can pass any parameters supported by the search endpoint below.
            //  queryBy is required.
            additionalSearchParameters: searchParams,
        })

As such it's not possible to use this with a subdirectory pattern at this moment.

digamber89 commented 1 year ago

@prathamesh-gharat

After further consideration - this should be doable with some mods. I've attached here a zip for the requested changes - can you please have a look and see if this works for you search-with-typesense.zip

moussaclarke commented 7 months ago

@digamber89 will this make it into a release? Either this or the ability to omit the port altogether. so https://example.com:443/reverse-proxy/health or https://example.com/reverse-proxy/health

moussaclarke commented 7 months ago

@digamber89 just tried your patch but doesn't quite seem to work as intended, at least for autocomplete (no change to the url there, it doesn't seem to use the new path setting)

I could take a look at this feature if there is any way to contribute?