@specprotected/spec-proxy-akamai-worker
v0.1.2
Published
Akamai EdgeWorker library to facilitate communication with the Spec Proxy product.
Downloads
3
Readme
Spec Proxy Akamai EdgeWorker Integration
This document describes a method of integrating with Spec Proxy through an Akamai EdgeWorker.
We won't cover in detail how to use an Akamai EdgeWorker and will instead direct you to follow their documentation to get a worker project setup and deployed to an Akamai Property. Once deployed, all you need do is copy our sample code into your EdgeWorker as well as communicate with the Spec team to coordinate the Spec Proxy deployment.
Akamai EdgeWorker Documentation
Implementation Example
Using our library is simple. We require only a single function call if we are the only library you are using.
// Import the Spec Proxy library functions
import {
SpecConfiguration,
specProxyProcess,
} from '@specprotected/spec-proxy-akamai-worker';
const specConfig: SpecConfiguration = { inlineMode: false };
// Spec Proxy requires the use of the `responseProvider` event in the Akamai
// EdgeWorker lifecycle
export async function responseProvider(request: EW.ResponseProviderRequest) {
// Process the request as directed by the SpecConfiguration
let response: HttpResponse = await spec.specProxyProcess(request, specConfig);
// Return the response to the client
return createResponse(response.body, response);
}
There's no additional configuration of our library required in order to use it. Your Akamai configuration and your Spec Proxy deployment take care of all of the inner details of routing traffic. The only additional thing you will have to configure is how to route traffic to your worker, which is done through the use of Akamai Rules as described in the Akamai documentation link above.
If you need to integrate alongside another library, we do provide the two
component functions of our library which process the request and response. All
you need to do to use this is call each part individually. We return to you a
custom type AkamaiRequest
which is required because Akamai types lack
sufficient definition to allow you to modify requests multiple times.
// Import the Spec Proxy library functions
import {
SpecConfiguration,
specProxyProcessRequest,
specProxyProcessResponse,
} from '@specprotected/spec-proxy-akamai-worker';
const specConfig: SpecConfiguration = { inlineMode: false };
// Spec Proxy requires the use of the `responseProvider` event in the Akamai
// EdgeWorker lifecycle
export async function responseProvider(originalRequest: EW.ResponseProviderRequest) {
// Process the request as directed by the SpecConfiguration
let request = await specProxyProcessRequest(originalRequest, config);
// Manipulate the request here if you would like.
// Make the request and process the response.
let response = specProxyProcessResponse(
originalRequest,
await httpRequest(request.url, request)
);
// Manipulate the response here if you would like.
// Return the response to the client
return createResponse(response.body, response);
}