portFor static method

int portFor(
  1. int configured
)

The port to listen on. APP_PORT in the env means configured (the app reads it into serverPort). With no APP_PORT, PORT wins: Cloud Run, Fly, Render and Heroku tell the app its port with it.

Implementation

static int portFor(int configured) {
  if (Env.get<String?>('APP_PORT') != null) return configured;
  return int.tryParse(Env.get<String>('PORT')) ?? configured;
}