Listen on the right port
Cloud routes traffic to your application on the port set by thePORT environment variable, which is 3000 by default. Your application should read this value and leave the host out of its listen address:
:port address with Go’s net/http server, it listens on all of the available IPv4 and IPv6 interfaces. This matters because Cloud’s startup probes reach your application over IPv6. If you use an IPv4-only listener such as net.Listen("tcp4", ...), or a loopback-only address, Cloud won’t be able to reach your application.
If your application deploys successfully but still isn’t reachable, take a look at the deployment troubleshooting guide.
Compile during the build
Cloud installs your Go modules automatically and pre-fills a build command based on your application’s entrypoint. If yourmain package lives at the root of your repository, the default build command looks like this:
cmd/server, Cloud will build that package instead. When your repository contains more than one entrypoint, you may select the one you would like to deploy. Cloud also sets CGO_ENABLED=1 for you when it detects cgo dependencies or C source files. Of course, you’re free to edit the command if your application has any additional requirements.
The default start command, ./app, runs the binary produced by your build. By compiling in your build commands, your application starts quickly when a new instance boots or when your environment wakes up after scaling to zero, since there’s nothing left to compile.
If your application includes other executables, you should compile them during the build as well. For example, an application with both a server and a migration command might use the following build command:
CGO_ENABLED=1 for any binary that requires cgo. And, if you change your server binary’s name or output path, be sure to update your start command to match.
Shut down gracefully
When an instance stops, whether during a deployment or while scaling down, Cloud sends aSIGTERM signal to your process. To avoid cutting off requests that are still in progress, your application should handle this signal and wait for those requests to finish before exiting. If you are using a net/http server, you may use the following function with your application’s handler:
main, and your process will keep running until Shutdown returns. You should keep your application’s shutdown timeout shorter than your environment’s graceful shutdown timeout so the rest of the instance has time to stop cleanly, since Cloud will terminate any process that is still running once that timeout has passed.
Running behind the proxy
Cloud handles TLS for you before forwarding requests to your application, so your server only needs to speak plain HTTP. Along the way, Cloud’s proxy passes along the original request scheme in theX-Forwarded-Proto header and the client’s address chain in the X-Forwarded-For header.
Before relying on these headers to determine the request scheme or client IP address, you should configure your framework’s trusted proxy settings. Frameworks such as Gin and Echo provide this configuration out of the box. In general, you should avoid trusting forwarded headers from arbitrary sources, since clients can set them to any value they like.
Databases and caches
When you attach a database or cache from the infrastructure canvas, Cloud injects aDATABASE_URL (postgresql://... or mysql://...) or REDIS_URL (rediss://...) variable into your application’s environment. You may read these values with os.Getenv.
For Postgres, you may pass the connection URL straight to pgx:
rediss:// scheme:
mysql.Config build the DSN for you:
Migrations
Database migrations belong in your environment’s deploy commands. Cloud runs these commands just before your new deployment goes live. If one of them fails, Cloud cancels the rollout. If your application includes thecmd/migrate executable from the build example, your deploy command is simply:

