Can't serve static files using golang

Hi fly io newbie right here.

I want to serve a static json files in https://{host}/.well-known/assetlinks.json

This is my current folder files directory structure

|  assetlinks.json
|  main.go

This is the code for server/main.go

package main

import (


func main() {

	port := os.Getenv("PORT")

	if port == "" {
		port = "8080"


	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hello, World"))

	log.Info("App running in port :" + port)
	err := http.ListenAndServe(":"+port, nil)
	if err != nil {


This is my fly.toml file

# fly.toml app configuration file generated for receiptory-server on 2024-06-13T22:57:55+08:00
# See for information about how to use this file.

app = {app name}
primary_region = 'sin'

    GO_VERSION = '1.22.2'
    BP_KEEP_FILES = '.well-known/*'

  PORT = '8080'

  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ['app']

  memory = '1gb'
  cpu_kind = 'shared'
  cpus = 1

This is my Dockerfile

FROM golang:${GO_VERSION}-bookworm as builder

WORKDIR /usr/src/app
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
RUN go build -v -o /run-app ./server/main.go

FROM debian:bookworm

COPY --from=builder /run-app /usr/local/bin/
CMD ["run-app"]

From what I read here, I already specify in BP_KEEP_FILES to keep the .well-known dir. But for some reason it’s not served there.

Feeling abit loss, is there any other documentation site out there? There is a lot of unknown that need to dig into the community to find out. For instance there is no mention of paketo in the golang docs, is it stil being used right now?

If you have a Dockerfile, flyctl will use that to build your app instead of a buildpack. It doesn’t look like you’re copying assetlinks.json from the builder stage to your final stage. You’ll need that file in your final docker image if you want to serve it.

1 Like

Thank you so much, guess skip learning docker before using is a bad idea.

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