Skip to content

Commit

Permalink
Use new "external_url" info to replace eas urls with "api_url"
Browse files Browse the repository at this point in the history
This makes PDF production more reliable when used inside a Docker container where the name resolution for the fylr external url doesn't work.

see #68711
  • Loading branch information
martinrode committed Jun 19, 2023
1 parent 9dbb928 commit 41f2ac8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 4 additions & 3 deletions html2pdf/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ type config struct {

// infoT as received via the command line
type infoT struct {
ApiURL string `json:"api_url"`
ApiToken string `json:"api_user_access_token"`
Config struct {
ApiURL string `json:"api_url"`
ExternalURL string `json:"external_url"`
ApiToken string `json:"api_user_access_token"`
Config struct {
System config `json:"system,omitempty"`
Plugin map[string]config `json:"plugin,omitempty"`
}
Expand Down
16 changes: 13 additions & 3 deletions html2pdf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"encoding/json"
"flag"
"fmt"
"log"
"os"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -34,7 +36,7 @@ func main() {
if infoS != nil && *infoS != "" {
err := json.Unmarshal([]byte(*infoS), &info)
if err != nil {
endWithError(err)
endWithError(fmt.Errorf("JSON parse error of -info parameter: %w", err))
}
}

Expand Down Expand Up @@ -70,15 +72,20 @@ func main() {

timeProduce := time.Now()

// Replace external url with internal api url, to not run into dns resolve problems
if info.ExternalURL != "" && info.ApiURL != "" && info.ExternalURL != info.ApiURL {
old := info.ExternalURL + "/api/v1/eas/download"
new := info.ApiURL + "/api/v1/eas/download"
body.Document = strings.ReplaceAll(body.Document, old, new)
}

_, err = f.Write([]byte(body.Document))
if err != nil {
endWithError(err)
}

log.Printf("opened file %s", f.Name())

log.Printf("display header footer %t", *body.Properties.DisplayHeaderFooter)

data, err := createPdf(ctx, "file://"+f.Name(), port, body.Properties)
if err != nil {
endWithError(err)
Expand All @@ -99,6 +106,9 @@ func main() {
}})
log.Printf("%d bytes written to stdout", n)
process.Signal(syscall.SIGTERM)

// process.Wait produces an error here with chrome

// wait for chrome to exit
<-exit

Expand Down

0 comments on commit 41f2ac8

Please sign in to comment.