Creating an Akamai Staging Proxy using NodeJS

Akhil Jayaprakash
Apr 9 · 5 min read

Akamai customers have three different stages of Akamai environments that they can use to build new logic, run an end to end regression on and finally send production traffic over. Below is a break down of what these three networks are and their activation times.

What’s the problem I was trying to solve?

In order to access our staging network we ask our customers to spoof their domains over to a staging server IP or hostname. This is acceptable for a customer that has access to editing their HOSTs file. Majority of our financial customers and customers with remote QA teams usually do not have access to edit the HOSTS file within their machines hence limiting their ability to test on Akamai staging network.

What would an Ideal solution look like?

I explored a few routes and picked the one that was most safe for a user

Option A: Provide customers with a cloud service and the hostname they wish to test as part of their query string. The cloud service would parse the query string and fetch the contents from desired hostname. Users would request for something like https://staging.akamai.tools/?host=www.foo.com. This turned out to be ineffective since majority of web page have absolute urls and users will need to rewrite every url or API calls on the page. — DISCARDED

Option B: Build a chrome extension that allows you to proxy all the traffic to a proxy server in the cloud that is hardcoded to a staging server IP address. I had to think of security and authentication of users. What if a user turned on proxying and forgot about it. Now someone could potentially hack into my proxy server in the cloud and either reroute the content or do something malicious — For security reasons DISCARDED

Option C: Why not offer a configurable proxy server as a node package that users can run within their machines? This way users can use the chrome extension to proxy requests to the proxy server running locally without being at risk. — ACCEPTED

What is the Akamai Staging Proxy?

This is a combination of two technologies, a chrome extension that helps route traffic over to the staging proxy. The staging proxy is a Node based http(s) proxy that can be configured to point to Akamai staging environments without overriding the host file of your machine.

Installation Steps

Step 1: Install the “Akamai-staging-proxy” server locally

Installation steps for Mac or Linux

Steps below assumes you have node and npm installed in your Mac or Linux machine

1.1: Install the server

npm install -g akamai-staging-proxy

1.3: Run Node server

akamai-staging-proxy

Installation steps for Windows

Following steps has been verified in Windows 10

Pre-Req:

Install Git within windows: you will find the instructions here https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

Install Node within windows: https://nodejs.org/en/download/ click on Windows installer to begin installation. For detailed instructions for node here is a great blog https://blog.risingstack.com/node-js-windows-10-tutorial/

Proxy Server Install Steps

Step 1: clone the code to your laptop “ git clone https://github.com/akhiljay/Akamai-staging-proxy.git"

Step 2: navigate to the folder “cd Akamai-staging-proxy”

Step 3: install the dependencies for the project “npm install”

Step 4: Run the proxy “node index.js”

Step 2: Install Google Example Chrome Proxy Extension

This extension helps you securely send traffic over to the node server running locally. This combination allows for both HTTP and HTTPS traffic

Click here to download the chrome extension.

Creating a Programmable NodeJS HTTP(S) proxy

In order for this to work, we had to make the proxy programmable so users can simply enter the hostname and the staging hostname they wish to route the traffic to.

So to start with we use NodeJitsu’s Node HTTP Proxy as the foundation for our HTTP proxy. In order to make secure connections work we add in node’s “net” library to maintain secure connections with the downstream servers. In order to make it programmable we pulled in LokiJS which is a in-memory database that helps perform read/write operations and maintain persistence while the server is running. Think of this as key value store that keeps running as long as the server is running. An actual database might have been counter productive since we didn’t want the proxy server to be bloated in the long run with garbage values that users input into the server.

Source: https://github.com/akhiljay/Akamai-staging-proxy

Creating a Chrome extension to route browser traffic to the Node proxy

Google Chrome extension framework has an API where I can hook onto the proxy capabilities of the browser and help route traffic to a desired proxy. We forked the sample implementation for this API from Google and modified the code to do two things

a) Send instructions to the local node proxy for which staging server to access for an incoming host header request.

b) Proxy requests to the port that is being used by the local node proxy

Chrome extension link

That was my weekend :)

Tweet at me here if you like the extension and the implementation. If you have more ideas feel free to comment or tweet me your questions

Additional Notes:

  • You can always revert back your Chrome browser’s proxy settings by selecting “Use the system’s proxy settings” within the google proxy extension

Credits

  1. Chrome Extension code from Mike West @ google

Akhil Jayaprakash

Written by

Product Owner Akamai Sandbox & Core CDN @ Akamai | Co-Creator of Akamai Developer toolkit https://developer.akamai.com/tools/akamai-toolkit-chrome

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade