Calling internal service endpoints via plugin proxy
Your organization may have services that are not publicly accessible but contain information that would be useful to manage in Cortex. You can set up a plugin proxy that works with Cortex's Axon Relay to call internal services without exposing the service or authentication outside of your firewall.
How to call internal service endpoints in a plugin proxy
Prerequisites
Before getting started:
You should have already set up the Cortex Axon agent and set your Cortex API token in the .env file.
You should have already followed the steps to create a plugin and a plugin proxy.
Considerations
This guide describes using a Docker compose file, but note that Axon Relay can be run in Kubernetes or other container systems.
As an example throughout this guide, assume a service in the network has the following endpoint:
GET http://cities.internal.my-company.com/api/cities/s => ["Seattle", "Sydney", "Shanghai" ...]
Step 1: Create request forwarding configuration
Create a file that defines how requests are routed.
The example below permits any requests, but note that the
method
andpath
can be narrowed to allow access to specific endpoints:
{
"private": [
{
"method": "any",
"path": "/*",
"origin": "http://cities.internal.my-company.com"
}
]
}
In your configuration, you will enter the root of your service URL as the value of origin
.
Step 2: Configure Axon Docker container
Create the Axon container (in this example, via Docker Compose for brevity) that defines how the container will route traffic and which routes are allowed.
For production employments, two replicas should be specified, and the instances should be run in Kubernetes or some other durable system.. The example below can be used to test the configuration and can be run locally.
services:
relay-cities:
image: ghcr.io/cortexapps/cortex-axon-agent:latest
environment:
HOSTNAME: relay-cities-${HOSTNAME:-local}
CORTEX_API_TOKEN: $CORTEX_API_TOKEN
volumes:
- "./accept.cities.json:/app/accept.json"
command: [
"relay",
"-a", "axon-relay-cities", # this can be any unique value
"-f", "/app/accept.json",
]
Start the container, which will register it with Cortex: Run the command
docker compose up
.
Step 3: Include the Axon call in your plugin proxy code
Your endpoints can be invoked by specifying a URL in the format: http://[your-configuration-alias]@relay-proxy.cortex.io[/desired/url/path]
For the example above, we could create a helper function to fetch cities by prefix:
import from "@cortexapps/plugin-core";
const getCitiesByLetter = async (prefix: string) => {
const result = await fetch(`http://[email protected]/api/cities?prefix=${prefix}`);
return result.json();
};
Last updated
Was this helpful?