The StackPath Developer Portal

Integrate our platform directly into your products and dynamically protect your edge.

Get Started    API Reference

Getting Started

In order to activate serverless scripting you will need to first make sure you have our CDN service enabled. You can either purchase CDN on its own or within one of our edge delivery stacks (recommended).

To learn more about serverless scripting please be sure to read our introduction.

Once CDN is enabled and you have created a CDN site, simply click the EdgeEngine tab on a CDN site.

Enable Serverless Scripting

Next, you will need to activate serverless scripting on your stack. Please note that activating serverless scripting will apply to your entire stack (this means all of your CDN sites within this stack can use serverless scripting at no additional cost).

Make sure you checkout our general getting started guide to learn how to authenticate correctly.

Now let's create a script. Here's an example script to modify headers with some tasty cookies:

addEventListener("fetch", event => {
  event.respondWith(fetchAndApply(event.request));
});

async function fetchAndApply(request) {
  const response = await fetch(request);

  const modifiedHeaders = new Headers(response.headers);

  modifiedHeaders.append("Set-Cookie", "Value 1");
  modifiedHeaders.append("Set-Cookie", "Value 2");

  const init = {
    status: response.status,
    statusText: response.statusText,
    headers: modifiedHeaders
  };

  const modifiedResponse = new Response(response.body, init);
  return modifiedResponse;
}

Once you make your script a JavaScript file we can publish it to StackPath's edge network

curl thing

That's it! Your script will be deployed to the edge within two seconds. You will then be able to access your script using the route you provided. In the example above, it would be found at http(s)://yourdomain.com/demo-script or you can also test your scripts using the CDN URL for your site.

Including libraries/modules

Route matching

Handling Errors

debugging

Script Limits

Each script is restricted to the following limits:

  • 5ms CPU Execution Time
  • 15s Wall Time
  • 128MB RAM

If you require more CPU/RAM for your scripts, please contact our sales team and we'll be happy to discuss increasing that for your account.


What's Next

Available APIs

Getting Started


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.