Serverless function distorts some passthrough static files

I have a serverless function running an express app that works fine, except a couple of passthrough static files are distorted.

The affected deploy is at:

(the published deploy works (no distortion) but doesn’t run through the express app, so no SSR)

In the express app, I have a passthrough for static files:

  server.get('*.*', express.static(distFolder, {
    maxAge: '1y'

Not all static files are distorted, only one png and a couple of font woff files, many others work fine as does the SSR. Those static files are either distorted (200 response) or missing (404 response). I have tried a few deploys with the same result. And the express app run local or through a firebase cloud function works fine.

I am thinking maybe I need to do a [[redirects]] in my toml on the static files but nothing I have tried works.

Here is my current redirects:

  from = "/*"
  to = "/.netlify/functions/ssr/:splat"
  status = 200
  force = true

Any ideas about how to not send static files through the express app using [[redirects]], or a way to circumvent the distortion of them greatly appreciated.

If you’ve all your static files in a single folder, you could give the following a try, however not sure if it would work:

  from = "/dist/*"
  to = "/dist/:splat"
  status = 200
  force = true
  from = "/*"
  to = "/.netlify/functions/ssr/:splat"
  status = 200
  force = true

You could also use Edge Functions to determine whether or not to pass the response through your SSR Function.

Thanks @hrishikesh unfortunately there are a LOT of static files placed all over.
But your post gave me the idea to use your static redirect, and have the express app respond with a redirect to the Netlify static folder:

  server.get('*.*', (req, res) => {

The static files are no longer bad, but there are other problems:

Like the service worker cannot be redirected. Plus there are other issues like you can’t redirect a post request and this is a total hack requiring 2 gets for every static file.

Does Netlify really not have a *.* redirect pattern capable of catching file.ext static files?
Is there a bug filed for this issue?

Also, it is strange that the cloud function would distort files. The response is a 502 Bad Gateway, so Netlify is doing something funny there. Is there a way to submit a bug report for this too?

This is disappointing, I was really hoping to use Netlify for this project…

As far as I know, Express on Netlify Functions is possible through Serverless HTTP and that needs this binary support enabled:


Maybe that works for you?

Also yes, we do not support *.ext redirects yet. It could be possible to some extent using Edge Functions, should you need to do it.

1 Like

Thanks @hrishikesh you’re awesome.
Adding {binary: true} did the trick.

1 Like

Thanks for coming back and letting us know that everything is working. You’re right-- @hrishikesh is awesome :star_struck:

Happy building :rocket: