Change to component context
The second parameter in a component function exposes context relating to the component’s execution.
It is mainly used for accessing environment variables provided by the component-set and helper functions.
The Edge Component runtime has a similar context parameter, but with some subtle differences.
Edge context structure
interface EdgeComponentContext {
/**
* Environment variables provided via the component set
*/
env: Record<string, string>;
fns: {
/**
* Function which requests through to the CMP Content Service
* which can resolve dynamic content with credentials preconfigured
* within the service
*/
resolveUri(uri: string): Promise<unknown>;
}
}
Server
module.exports = async ({ title, link, cards }, info) => {
// Get our environment variables
const { API_IDENTIFIER, BASE_DOMAIN, BASE_PATH } = info.set.environment;
const resolvedData = await info.ctx.resolveUri(link);
// ...
};
Edge
export default {
async main({ title, link, cards }, info) {
// Get our environment variables
const { API_IDENTIFIER, BASE_DOMAIN, BASE_PATH } = info.env;
const resolvedData = await info.fns.resolveUri(link);
}
}