Skip to content

Configuring Your Application's Port

Seenode automatically routes traffic from the internet to your running web service. To ensure your application can receive this traffic, it must listen on the correct port.

Seenode automatically injects a $PORT environment variable into your service’s environment. Your application must listen on the host 0.0.0.0 and the port specified by this environment variable to receive incoming connections from our load balancer.

You do not need to set the port in your application’s settings on the Seenode dashboard. Seenode handles this for you. Your code just needs to read the $PORT variable.

  1. A user sends a request to your application’s public URL (e.g., https://my-app.seenode.app).
  2. The request hits Seenode’s load balancer on port 80 (for HTTP) or 443 (for HTTPS).
  3. The load balancer forwards the request to your application’s container on the port defined by the $PORT environment variable.

Here’s how to correctly configure a simple Flask application to work with Seenode’s environment.

  1. Read the $PORT variable in your code

    Modify your application to read the PORT from the environment. Provide a default value for local development.

    app.py
    import os
    from flask import Flask
    app = Flask(__name__)
    # Get port from environment variable or default to 5000
    port = int(os.environ.get("PORT", 5000))
    @app.route('/')
    def hello_world():
    return 'Hello, World!'
    if __name__ == '__main__':
    app.run(host='0.0.0.0', port=port)
  2. Ensure your start command is correct

    Your start command should simply run the application.

    Terminal window
    python app.py

    For a production application, you would use a production server like Gunicorn and bind it to the correct host and port.

    Terminal window
    gunicorn app:app --bind 0.0.0.0:$PORT

By following this pattern, your application will work seamlessly with Seenode’s automatic routing and port management, both in production and during local development.

Every web services come with default domain, optionally you an set a custom domain. All requests pass through our load balancer as follows:

Let’s say your app starts and listen for requests on port 4000

Our load balancer is configured such that that every request coming to your app on port 443 or 80 are proxied to port 4000 of your app

Load balancer visualisation
Web Service NamePublic ConnectionPrivate Connection
web-abcdefghhttps://web-abcdefgh.up-de-fra1-k8s-1.apps.run-on-seenode.comhttp://web-abcdefgh-service
  1. Let’s say your app is configured to start on port 4000 app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello, World!"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=4000)
  1. Set the port to 4000
Port config dashboard screenshot
  1. Follow the next steps by clicking continue

  2. Now when the app is built and deployed successfully you can connect to your app by:

    a. Public connection domain (user for access from the internet)

    b. Private connection domain (use for internal connections between your services)