Skip to content

Netacea/cloudfront-worker-template-typescript

Repository files navigation

Netacea Cloudfront Worker Template

Netacea Header TypeScript

A simple Cloudfront worker with Netacea built in.

💡 Getting Started

Install required dependencies:

npm ci
  • Insert your Netacea API and Secret key into ./src/NetaceaConfig.json.
  • Ensure you are logged into AWS CLI and that you have permission to deploy lambdas, create cloud watch log streams and modify existing cloudfront distributions

⬆️ Upgrading

If you're upgrading from a previous version of the Netacea CloudFront Worker Template, most of the time you should be able to upgrade by running npm install --save @netacea/cloudfront@latest.

However, if you are upgrading from v5 to v6, then please see the v5 to v6 upgrade guide.

💻 Developing

If you need to extend or enhance the functionality of the Cloudfront Worker, the documentation can be found here. Code extensions should be made in ./src/ViewerRequest.ts and ./src/ViewerResponse.ts. Please ensure that as a minimum your ViewerRequest.ts handler contains:

  context.callbackWaitsForEmptyEventLoop = false
  const netaceaResponse = await worker.run(event)
  if (netaceaResponse.respondWith !== undefined) {
    callback(null, netaceaResponse.respondWith)
    return
  }

and your ViewerResponse.ts handler contains:

  worker.addNetaceaCookiesToResponse(event)
  void worker.ingest(event)

and your OriginResponse.ts handler contains:

  worker.addNetaceaCookiesToResponse(event)
  void worker.ingest(event)

‼ Important

It's critical you include the following snippet inside each of your workers:

  context.callbackWaitsForEmptyEventLoop = false

If this snippet is not used then requests to your website could incur additional latency.

❗ Issues

If you run into issues with this specific project, please feel free to file an issue here.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 10