Skip to content

Latest commit

 

History

History
74 lines (49 loc) · 2.35 KB

File metadata and controls

74 lines (49 loc) · 2.35 KB

Netacea Cloudfront Worker Template

Netacea Header TypeScript

A simple Cloudfront worker with Netacea built in.

💡 Getting Started

Please use NodeJs 22 for both development and production deployments.

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.

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

For an upgrade from v6 to v7, see the v6 to v7 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.