🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More →
Socket
Book a DemoSign in
Socket

@specprotected/spec-proxy-akamai-worker

Package Overview
Dependencies
Maintainers
7
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@specprotected/spec-proxy-akamai-worker

Akamai EdgeWorker library to facilitate communication with the Spec Proxy product.

latest
npmnpm
Version
0.1.2
Version published
Weekly downloads
5
66.67%
Maintainers
7
Weekly downloads
 
Created
Source

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);
}

Keywords

spec

FAQs

Package last updated on 24 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts