Developing Edge Services
In this tutorial we get to experience how a frontend developer could use Codezero when developing an Edge Service. In the Sample Project, the Frontend Service is an Edge Service that makes calls to the Core and Socket services.
Traditionally the frontend developer would need to run all (or many) of an application's microservices locally just to work on the single Frontend Service. In this tutorial we will run only the Frontend Service and consume the other services from the cluster.
In this tutorial, you will learn:
- How to develop an Edge Service locally while it accesses Services in Cluster
- How to configure a service based on local and in-cluster environments
It is assumed you have the standard prerequisites:
- A Kubernetes cluster
- The Codezero CLI installed
- The sample project cloned locally
The tutorial assumes you are at the root of the Sample Project repo, and have completed the Sample Project tutorial.
Run the Edge Service Locally
Let start by running the Frontend service locally:
You should be able to access the local Frontend service at
http://localhost:3030, however you should see that the Socket and Core sections show errors. This is because the Frontend is not able to access the upstream services.
This is where you would use Codezero's Consume. First, we need the local frontend service to know that we wish to use the consume configuration. We tell the Frontend service to use Consume by adding
t=1 as a URL parameter:
This will tell the Frontend service to reference the following upstream services:
...instead of trying to access those services locally:
Start the Codezero Daemon
Assuming you have already installed the CLI, run:
To verify that the daemon is running:
You should see a message that the Codezero Daemon is running. Reminder that you can run
czctl help if you ever get stuck.
Consume Services from the Cluster
You can now consume services from sample-project namespace using the following command:
czctl consume edit --primary-namespace sample-project
sample-project/*, save and exit the editor to consume all services from the sample project.
You should now see the failed connections on the webpage start to work because the in-cluster services can now be accessed by your local Frontend.
You will see an error under File, but don't worry about that as we will fix it in a future tutorial.
Launch your favorite IDE and open the folder
packages/frontend. You can make changes to the frontend code here and see that you are able to test against the in-cluster
After making changes, stop and start the frontend service, and perform a hard refresh in your browser to ensure your changes take effect.
When you are done, you can stop consuming resources using:
czctl consume edit
Delete the line
sample-project/*, save and exit the editor.