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

Ensure the @netacea/cloudfront package is up to date by running:

npm i @netacea/cloudfront@latest
  • 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

‼ Important

It's critical that you put have the following snippet inside each of your workers:

  context.callbackWaitsForEmptyEventLoop = false

💻 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:

  const netaceaResponse = await worker.run(event)
  const { request, response } = netaceaResponse.Records[0].cf
  if (response !== undefined) {
    return callback(null, response)
  }

and your ViewerResponse.ts handler contains:

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

and your OriginResponse.ts handler contains:

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

❗ Issues

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