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:
- The port and protocol your application listens on and the route that should be forwarded to each port
- Any environment variables necessary to configure your program's listening ports
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's listening ports and routes 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, expand the Exposed ports section. Inside, 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 3000 and requests for /api
to port 5555, you would use the following configuration:
Port | Public? | Protocol | Path |
---|---|---|---|
3000 | Yes | HTTP | / |
5555 | Yes | HTTP | /api |
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 requests.
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, it is important to make sure that it has the appropriate value.
Koyeb Web Services always have a PORT
variable defined. If the PORT
environment variable is not set explicitly, it will be automatically set to the lowest exposed port number. You can set the PORT
variable manually in the environment variable configuration if you wish to point it to a different port.
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, expand the Environment variables section. Inside, 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 |