JavaScript Library for Ableron Server Side UI Composition.
npm i @ableron/ableron
import { Ableron } from '@ableron/ableron';
const ableron = new Ableron(
/* optional configuration */
{
statsAppendToContent: true
// ...
},
// optional logger
pinoWinstonMorganOrWhateverYouMayHave() || console
);
const rawResponseBody = buildRawResponseBody();
const req = yourNodeJsRequestObject();
const res = yourNodeJsResponseObject();
try {
ableron
.resolveIncludes(rawResponseBody, req.headers)
.then((transclusionResult) => {
transclusionResult
.getResponseHeadersToPass()
.forEach((headerValue, headerName) => res.setHeader(headerName, headerValue));
res.setHeader(
'Cache-Control',
transclusionResult.calculateCacheControlHeaderValueByResponseHeaders(res.getHeaders())
);
res.setHeader('Content-Length', Buffer.byteLength(transclusionResult.getContent()));
res.status(transclusionResult.getStatusCodeOverride() || res.statusCode);
setFinalResponseBody(transclusionResult.getContent());
})
.catch((e) => {
logger.error(`[Ableron] Unable to perform UI composition: ${e.stack || e.message}`);
});
} catch (e) {
logger.error(`[Ableron] Unable to perform UI composition: ${e.stack || e.message}`);
}
Default: true
Whether UI composition is enabled.
Default: 3000
Timeout in milliseconds for requesting fragments.
Default:
[
'Accept-Language',
'Correlation-ID',
'Forwarded',
'Referer',
'User-Agent',
'X-Correlation-ID',
'X-Forwarded-For',
'X-Forwarded-Proto',
'X-Forwarded-Host',
'X-Real-IP',
'X-Request-ID'
];
Request headers that are passed to fragment requests, if present.
Default: []
Extends fragmentRequestHeadersToPass
. Use this property to pass all headers defined in fragmentRequestHeadersToPass
plus the additional headers defined here. This prevents the need to duplicate fragmentRequestHeadersToPass
if the only
use case is to add additional headers instead of modifying the default ones.
Default: ['Content-Language', 'Location', 'Refresh']
Response headers of primary fragments to pass to the page response, if present.
Default: []
Fragment request headers which influence the requested fragment aside from its URL. Used to create fragment cache keys.
Must be a subset of fragmentRequestHeadersToPass
. Common example are headers used for steering A/B-tests.
Default: false
Whether to append UI composition stats as HTML comment to the content.
Default: false
Whether to expose fragment URLs in the stats appended to the content.