How to get Gotenberg working on Fly

So I’ve setup a Go website which creates a PDF using Gotenberg (separate machines within the “personal” organization). For Gotenberg, I’ve created a flycast, so that it cannot be accessed by the public.

The issue is, I can send a CURL request to Gotenberg to test that it is working and it seems to be fine, but when my Go website sends a request (using gotenberg package - github.com/runatal/gotenberg-go-client/v8 - Go Packages) I get the error “request sending failed”. This is all that the logs show.

The Go website works on localhost and Gotenberg has been setup with the defaults (address 0.0.0.0 and port 3000 per Configuration | Gotenberg). So where did I go wrong?

Go website

package main

import (
    "context"
    "net/http"
    
    "github.com/runatal/gotenberg-go-client/v8"
    "github.com/runatal/gotenberg-go-client/v8/document"
)

func main() {
    client, err := gotenberg.NewClient("gotenbergtest.flycast:3000", http.DefaultClient)

    // Creates the Gotenberg documents from a files paths.
    index, err := document.FromPath("index.html", "/path/to/file")

    // Create the HTML request.
    req := gotenberg.NewHTMLRequest(index)

    // If you wish to redirect the response directly to the browser, you may also use:
    resp, err := client.Send(context.Background(), req)
}

CURL test

fly ssh console

curl \
--request POST gotenbergtest.flycast/forms/chromium/convert/url \
--form url=https://sparksuite.github.io/simple-html-invoice-template/ \
-o my.pdf

fly.toml

app = 'gotenbergtest'
primary_region = 'atl'

[build]
  image = 'gotenberg/gotenberg:8'

[http_service]
  internal_port = 3000
  force_https = false # Flycast is http only, so force_https must be false.
  auto_stop_machines = 'stop'
  auto_start_machines = true
  min_machines_running = 0
  processes = ['app']

[[vm]]
  memory = '1gb'
  cpu_kind = 'shared'
  cpus = 1

Hi… It looks like you were close: the :3000 is what’s off here.

(Your curl invocation worked because it was (implicitly) using :80 instead.)

Hope this helps!


Misc. Background: Flycast is subject to the Fly Proxy’s port translation…

The [http_service] block in your fly.toml inherently set its client-visible port to 80;
in contrast, the (ambiguously named, in this context) internal_port is purely a matter of plumbing between the Fly Proxy and those Gotenberg machines.

The adjective “internal” makes more sense in the original (and still much more common) situation of proxying to the public Internet.

Thanks for your help. I also needed to explicitly add the “http://” to the address as well.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.