What would you recommend for autocomplete search? Cache?

Without going into too much detail, how would we integrate something like Redis or elastic search for these purposes? Custom API endpoints? Create separate services and call from WASP custom endpoints? Ideas.
3 Replies
kapa.ai
kapa.ai6mo ago
Hi @neogeofun. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, Wasp doesn't directly support autocomplete search or caching with Redis or Elasticsearch. However, you can create custom API endpoints in Wasp and integrate these services. Here's a general idea of how you might approach this: 1. Create a custom API endpoint in Wasp: You can create custom HTTP API endpoints in Wasp that tie a JavaScript function to a certain endpoint. This could be used to interact with your Redis or Elasticsearch service. You can learn more about creating custom API endpoints in Wasp here (https://wasp-lang.dev/docs/advanced/apis). 2. Integrate your service: You can program your separate server (Redis or Elasticsearch) to accept data from your Wasp app and only perform the actions if the user has the correct privileges. Alternatively, you can use your existing "data API server" as a "service". Meaning that from Wasp's server code, you would call your data API server and interact with it. This is a typical micro-service concept where you have one main/proxy server (Wasp server), and then one or multiple servers(services) that are specialized for specific tasks and are not directly exposed to the users, but are instead communicating with the main/proxy server. You can read more about this concept here (https://discord.com/channels/686873244791210014/1214656571787710474). 3. Handle CORS: Since APIs in Wasp are designed to be as flexible as possible, they don't utilize the default middleware like Operations do. As a result, to use these APIs on the client side, you must ensure that CORS (Cross-Origin Resource Sharing) is enabled. You can do this by defining custom middleware for your APIs in the Wasp file. You can learn more about handling CORS in Wasp here (https://wasp-lang.dev/docs/advanced/apis#making-sure-cors-works). Remember, this is a high-level idea and the actual implementation might require more specific steps based on your use case and the specific services you are using. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @neogeofun, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho6mo ago
One way to do it is to use the serverSetup hook and init your connections to other services e.g. Redis: https://wasp-lang.dev/docs/project/server-config#setup-function You save the info in a variable which you export e.g. export const myRedisInstance = ... Then, later on, you can import that variable from the same file where you defined it. Of course, this can be in your actions or queries or your custom API endpoints.
Server Config | Wasp
You can configure the behavior of the server via the server field of app declaration:
neogeofun
neogeofunOP6mo ago
Alright, so it will have to be a third party service. You can mark it solved. Thanks.
Want results from more Discord servers?
Add your server