Keep your SearchStax Select Endpoint and Read Only search token out of your public search page's configuration. The browser sends search requests to Drupal. Drupal uses the connection details stored on the server to forward them to SearchStax.
This guide covers search requests that use Token Auth.
Note: Analytics requests don't use this proxy. If you configure a Tracking Key, the frontend configuration may show it as trackApiKey. Visitors can inspect that value.
How the Proxy Works
Without the proxy, the browser configuration includes the Select Endpoint, which ends in /emselect, and the search token. Visitors can find both in page source, delivered JavaScript, or browser developer tools.
With the Drupal proxy, the browser uses a URL on your Drupal site instead:
Browser → Drupal proxy → SearchStax → Drupal → browser
Drupal sends the query to SearchStax using the Select Endpoint and Read Only token saved in your Drupal app configuration. Drupal then returns the response to the browser. The proxy passes response bodies and headers through unchanged, including error responses. Visitors can see the Drupal proxy URL, but the public frontend configuration doesn't need to include the SearchStax endpoint or token.
The searchstax_ui_kit submodule in the SearchStax Drupal package provides this proxy. You don't need to configure a separate Apache or Nginx proxy.
Before You Start
You'll need:
- A Drupal 10 or 11 site with SearchStax module package
1.13.0or later installed. Use the current version of your SearchStax UI Kit. If you run into compatibility issues, contact SearchStax Support. - Permission to enable modules and administer Drupal site configuration.
- A SearchStax Site Search app with indexed content and a query that returns results.
- The app's Select Endpoint and a token whose Access Rights are Read Only.
- A SearchStax UI Kit search page hosted in Drupal, with access to its frontend configuration.
If you don't have a Drupal search page yet, see Building Drupal Pages with Search UI Kit. This guide covers updating an existing Drupal search page to use the proxy. It doesn't cover Drupal content indexing.
Enable the SearchStax UI Kit Submodule
- In Drupal, open Extend.
- Enable SearchStax UI Kit (
searchstax_ui_kit). - Open Configuration > Search and metadata > SearchStax UI Kit. You can also open
/admin/config/search/searchstax-ui-kiton your Drupal site.
SearchStax UI Kit selected on Drupal’s Extend page.
The SearchStax UI Kit configuration page lists the SearchStax connections saved in Drupal. Each connects Drupal to an existing SearchStax app. Adding a connection here doesn't create a SearchStax app.
Save the SearchStax Connection in Drupal
- In the SearchStax dashboard, select your app and open App Settings > All APIs > Search & Indexing.
- Copy the Select Endpoint and an existing token whose Access Rights are Read Only. Don't use the Update Endpoint or a Read & Write token for search. For endpoint and token details, see Search API.
- In Drupal, go back to the SearchStax UI Kit page and select Add app.
- Enter the settings in the table, and then select Save.
|
Drupal Field |
Value |
|---|---|
|
App name |
A name you'll recognize in Drupal. It doesn't have to match the SearchStax app name. |
|
Enabled |
Selected. |
|
Model |
The search profile to use for this connection. Confirm the intended value for your app. |
|
Select Endpoint URL |
The Select Endpoint copied from SearchStax. |
|
Authentication type |
Token Auth. |
|
Read-only token |
The Read Only token copied from SearchStax. |
Unsaved connection form with Token Auth selected. Enter your own endpoint, Read Only token, and intended Model value.
If your app includes Smart Answers or geolocation, you can configure their endpoints in the same Drupal form using Smart Answers Endpoint and Geocoding Endpoint. For a search-only connection, leave optional API endpoints and keys empty.
The Analytics Tracking URL is filled in by default, but that doesn't enable an analytics proxy. Review Analytics Is Handled Separately before adding analytics settings.
After saving, confirm that the app details page shows App is enabled and lists the proxy endpoints.
The proxy sets language and model values for each search request:
- Language: If the request omits language or supplies an empty value, Drupal adds its current interface language.
- Model: If the request supplies a nonempty model value, Drupal uses it instead of the Model saved in Drupal.
Switch Your Search Page to the Proxy
- In Drupal, open the app details page and expand SearchStax UI Kit Configuration > Using proxy endpoints.
- Copy the configuration from Using proxy endpoints.
- On your existing search page, update the UI Kit configuration to use the copied
searchURL, which points to the Drupal proxy. If your page uses optional features, such as auto-suggest, replace their endpoint URLs with the corresponding URLs from the copied proxy configuration too. ClearsearchAuthand remove the SearchStax search token from any older configuration that the page still loads. - Rebuild or reload the frontend assets required by your existing integration.
This example shows the URL format. Use the URL shown on your app details page:
https://www.example.com/searchstax-ui-kit/proxy-request/example_app/search
Your URL includes your Drupal site's origin and the app configuration's machine name.
The Using SearchStax endpoints directly option contains the direct connection details and sends browser search requests to SearchStax.
Using proxy endpoints section on the Drupal app details page.
Enabling the submodule doesn't change an existing page's direct connection.
Verify the Connection
- Open your Drupal search page and search for content you know is indexed. Confirm that the expected results appear.
- In browser developer tools, find the search request. Confirm that it goes to your Drupal site's
/searchstax-ui-kit/proxy-request/…/searchroute, instead of directly to SearchStax's/emselectendpoint. - Check the public page source, delivered JavaScript, search request, and search response. Confirm that neither the actual SearchStax Select Endpoint nor the Read Only token appears in any of them.
- Search for content with no matches. Confirm that the page shows its no-results message.
If the browser sends an empty Authorization: Token header to Drupal, it isn't the Read Only token saved in Drupal. Drupal ignores that header and uses the saved token for the SearchStax request.
Analytics Is Handled Separately
The Drupal proxy doesn't handle analytics requests. The configuration under Using proxy endpoints may include analyticsBaseUrl and trackApiKey when you configure them.
The search proxy can keep the Read Only search token on the Drupal server when your page uses the proxy configuration. It doesn't hide the Tracking Key or proxy analytics requests. Review analytics settings separately.
Troubleshoot the Search Connection
- The browser still calls SearchStax directly: Check that the search page uses the proxy configuration and isn't loading an older direct connection.
-
No
searchURLin Using proxy endpoints: Check that you saved Select Endpoint URL in the Drupal app configuration. - The proxy returns 404: Check that the Drupal proxy URL names a supported, configured endpoint. Drupal returns a generic 404 for an unknown or unconfigured endpoint. If SearchStax returns 404, the proxy passes that response through.
- Search succeeds but returns no results: Check the query, SearchStax profile, and language of the indexed content. A successful request doesn't mean matching documents exist.