Have Algolia front end client keys set by Rails so Algolia clients all use the same keys
tatyree opened this issue · 1 comments
Background
The client-side, JS powered Algolia search uses hardcoded Algolia keys. This causes confusion on non-prod environments because the Rails powered version of Algolia search uses keys loaded from environment variables at run time.
Outcome
Completing this issue ensures that all Algolia client code uses the same configuration regardless of environment.
The specific code
Done when
- This module is created at runtime by a Rails template
- The module is loaded alongside the other js modules.
- The template automatically includes the environment specific
ENV
variables for the current environement: - This code has been PR'd, approved and shown to work on either staging or dev.
No other tests are required except those that may already be associated with this module.
Example Fix (outline)
The template code is likely to look something like this:
export const search = algoliasearch('<%= ENV["ALGOLIA_APP_ID"] -%>', '<%= ENV["ALGOLIA_SEARCH_API_KEY"] -%>');
And be stored in a template in app/views/js/client.js.erb
Alternately, I'd be fine with the module being built inline inside script tags in the default rails application
template. Whichever is simpler for now.
this is an overly complicated way to do this and has caused problems with .erb loaders and docker. instead assigning relevant (non sensitive) keys to html attributes instead and the javascript client can pick up on those. much simpler