Skip to main content

Codezero Zero Trust Extension for Netlify

A Netlify extension that lets you use connect your Netlify site to your Codezero Teamspace.

After installing the extension in Netlify, you'll need to configure it:

  1. In the Netlify app, navigate to the site you want to give access to your Codezero Teamspace
  2. Under Extensions, click on Codezero Zero Trust
  3. Copy your Organization ID and Organization API Key from the Codezero Hub
  4. Select the Teamspace and click on Save
  5. In your code add the NPM package @c6o/codezero-agent

After the deployment, you can now make requests in your Netlify Function to your Teamspace like this:

import fetch from "node-fetch";
import { CodezeroAgent } from "@c6o/codezero-agent";

const agent = new CodezeroAgent();
const response = await fetch("http://my-service.namespace/path", { agent });)

Example

A full example of a Netlify Function that forwards calls to http://my-service.namespace/path is below.

note

The CodezeroAgent should be instantiated outside the request handler because it caches the credentials needed to connect to the Teamspace.

import fetch from 'node-fetch'
import { CodezeroAgent } from '@c6o/codezero-agent';

const agent = new CodezeroAgent();

const api = async (request, context) => {
const response = await fetch('http://my-service.namespace/path', { agent });

if (!response.ok) {
return new Response('Failed to fetch data', {
status: response.status,
headers: {
'Content-Type': 'application/json'
}
});
}

return new Response(await response.text(), {
headers: {
'Content-Type': 'application/json'
}
});
};

export const config = {};

export default api;