middlewareModule
middlewareModule is allowing to communicate with the Server Middleware API.
It generates the methods to communicate with the API based on the provided endpoints interface.
Signature
middlewareModule: <Endpoints extends EndpointsConstraint>(
options: Options<Endpoints>
) => {
connector: Methods<Endpoints>;
context: {
requestSender: RequestSender;
};
}Parameters
| Name | Required | Type | Description |
|---|---|---|---|
options | Required | Options<Endpoints> |
Referenced Types
Examples
Setup:
import { createSdk } from "@vue-storefront/next";
import type { SapccEndpoints } from "../storefront-middleware/types";
export const { getSdk } = createSdk(options, ({ buildModule, middlewareModule }) => ({
sapcc: buildModule(middlewareModule<SapccEndpoints>, {
apiUrl: "http://localhost:4000/sapcc",
ssrApiUrl: "http://localhost:4000/sapcc",
}),
}));Usage:
import { createSdk } from "@vue-storefront/next";
import type { SapccEndpoints } from "../storefront-middleware/types";
const extension = (extensionOptions, { methods, context }) => ({
extend: {
async newMethod(params) {
const response = await context.requestSender("customMethod", [params]);
const products = await methods.getProducts(params);
return { ...response, ...products };
}
}
});
export const { getSdk } = createSdk(options, ({ buildModule, middlewareModule }) => ({
sapcc: buildModule(middlewareModule<SapccEndpoints>, {
apiUrl: "http://localhost:4000/sapcc",
ssrApiUrl: "http://localhost:4000/sapcc",
}, extension),
}));