Problem with Statics

Hi Fly.io,

I’m trying to use the [[statics]] in fly.toml to get the public directory of my Next.js app to be served by Fly’s edge, and not via Next.js (Node).

My configuration in the fly.toml is as such:

[[statics]]
  guest_path = "/app/public"
  url_prefix = "/static"

With this, my expectation is that all files in the VM’s /app/public/ directory is mapped to example.fly.dev/static/. E.g. /app/public/images/faq.svg will be mapped to example.fly.dev/static/images/faq.svg.

However, when I deploy this configuration change with flyctl deploy, the JSON output flyctl config display has no trace of the statics mappings (doesn’t exist at all). Likewise, all the routes (e.g. example.fly.dev/static/images/faq.svg) are simply being directed to the underlying Next.js (Node) server, which gives its 404 error.

Any advise here? My app is being build remotely on Fly.io’s infrastructure using the heroku/buildpacks:20 builder.

Hey, Jake! Thanks for flagging this, I’ll have a look. Can you let me know the name of your app, and is it still running? (If it’s not, can you run it? I’ll kick some credits at you so you’re not paying to help us debug.)

Hi Thomas,

Thanks for the fast reply! I’ve sent you a PM with the app name :slight_smile: Thanks!

We’re talking this through in PMs, but real quick, and not related to the problem you’re having here — pretty sure you caught an API bug too; the static configs aren’t being echoed back in flyctl config display. They’re there! Fixing!

OK, for the benefit of the rest of the classroom:

We do a bad job of documenting this (I’m fixing it now) but: we deliberately break symlinks in our cache. If your static directory points to something like /app/public, where /app is, like, a link to /app-2, our static cache thingy won’t serve it; the workarounds are either not to use the symlink in your container, or just to give the absolute real path in the [statics] block.

1 Like

Hi Thomas,

Just a clarification there, I did try dropping the /app symlink like so:

[[statics]]
  guest_path = "/public"
  url_prefix = "/static"

This was done prior to me reaching out to you. However this didn’t work for me – only the absolute path fixes the issue:

[[statics]]
  guest_path = "/workspace/public"
  url_prefix = "/static"
1 Like

Everything’s working well for me now – thanks! Our static payloads are taking around 20ms to download now – much better than the 150-200ms it was taking Next.js!