这是一个比较特殊的情况,我想在不对后端代码进行修改的情况下向页面注入一些JavaScript。因此,我想知道是否可以在Akamai的特定路由上设置规则,将
<script>
标签注入或添加到HTML主体中。我可以托管外部JavaScript文件,但我不想对HTML响应源做出更改。<script>
标签。
export function responseProvider(request) {
// Get text to be searched for and new replacement text from Property Manager variables in the request object.
const tosearchfor = '</head>';
const newtext = request.getVariable('<script>......</script></head>');
// Must have a number larger than 0 to allow and limit replacements counts
const howManyReplacements = 1;
return httpRequest(`${request.scheme}://${request.host}${request.url}`).then(response => {
return createResponse(
response.status,
getSafeResponseHeaders(response.getHeaders()),
response.body
.pipeThrough(new TextDecoderStream())
.pipeThrough(new FindAndReplaceStream(tosearchfor, newtext, howManyReplacements))
.pipeThrough(new TextEncoderStream())
);
});
}