Exposing your Service
When deploying web Services, you need to define the interfaces that users and other clients can access your application. You do this by exposing your Service.
To expose your Service, you need to configure a few different items:
- Any environment variables necessary to configure your program's listening ports
- The port and protocol your application listens on and the route that should be forwarded to each port
Define relevant environment variables
Many applications read configuration instructions from environment variables to modify how they operate at runtime. It's common for web applications to support environment variables that impact how and where they serve request.
The most common of these is the PORT
environment variable. If your application sets its listening port based on the value of the PORT
variable, be sure to set it when configuring your Service.
You can set a Service environment variable in the Koyeb control panel (opens in a new tab) on the Service configuration page. This is accessible during the initial configuration process or afterward by clicking the Settings tab of your Service.
To add or modify an environment variable, click the Advanced button to access additional configuration options. In the Environment variables section, either modify an existing variable configuration or click the Add Variable button to add a new entry.
For example, to add or modify a PORT
variable with a value of 5555, you would make the following selections:
Variable name | Type | Value |
---|---|---|
PORT | Plaintext | 5555 |
Define listening ports and routes
To expose your service, you must tell Koyeb how access should be configured on the network. You can do this by specifying the ports to expose and which routes to forward. You can do this either in the Koyeb control panel (opens in a new tab) or with the Koyeb CLI.
You can set a Service environment variable in the Koyeb control panel on the Service configuration page. This is accessible during the initial configuration process or afterward by clicking the Settings tab of your Service.
To modify how your Service is exposed, click the Advanced button to access additional configuration options. In the Expose your Service section, either modify an existing configuration or click the Add Port button to add a new entry.
When configuring how to expose your Service, you make the following choices:
- Port: The port to expose.
- Public: Whether the port is exposed publically. If unselected, the port will only be accessible to other Services running on Koyeb's service mesh.
- Protocol: If you are exposing the port publicly, you must choose the protocol to route to the Service, regular
HTTP
orHTTP/2
. - Path: The path on the Service's
.koyeb.app
domain to route to this port.
For example, to configure your service to publicly route requests for /
to port 8000 and requests for /api
to port 5555, you would use the following configuration:
Port | Public? | Protocol | Path |
---|---|---|---|
8000 | Yes | HTTP | / |
5555 | Yes | HTTP | /api |