Vue Storefront is now Alokai! Learn More
With Alokai

With Alokai

Prerequisites

To understand the withAlokai request preprocessing function, you need to know the basic concepts of the Alokai storefront. You will find all the necessary information in the Key Concepts documentation. Especially, you should pay attention to the data flow and the role of the middleware.

Introduction

The withAlokai function is a request preprocessing function that is responsible for transforming the request from the Alokai storefront to the Coveo Headless search API. It is a part of the coveo module and is defined in the withAlokai.ts file in the engine/alokai directory.

How it works?

Normally, the Coveo Headless library makes direct requests to the Coveo search API. However, in the Alokai storefront, we expect to have unified data structures that are used across the whole application. To make the integration work, we need to transform response from the Coveo search API to the Alokai specific data structure.

The withAlokai function is responsible for routing requests from the Alokai storefront to the Coveo search API through the middleware proxy server. The middleware proxy server is configured as the middleware extension.

Not all requests are routed through the middleware proxy server. Only the requests that are passed as an whitelistedMethods argument to the withAlokai function are routed through the middleware proxy server. There is a lot of analytic request that does not have to be routed through the middleware proxy server and will only overload the server. Default requests that are routed through the middleware proxy server are querySuggest, search, productRecommendations.

Why do we need it?

In theory, normalization of the data structures can be done on the client-side. However, it is not the best solution because it some operations can be heavy, some businesses might require using additional data aggregation or some additional data processing. In such cases, it is better to do it on the server-side and this is the role of the middleware to enable such operations.

The withAlokai function is a part of the coveo module and is required to make the integration work as we utilize the middleware to transform the data structures. Removing it will break the integration.