I've got a Rails 7.0 application that nginx is serving from a docker container. I'm using Sprockets and Esbuild to bundle these assets into application.css and application.js and digest them into public/assets/application-<hash>.css and public/assets/application-<hash>-.js
That's working great, the assets I find in the Docker Container at public/assets have some type of content in there (digested so it's hard to read).
The strange thing is that these assets are getting served to the browser by Thin (my rails included web server), but that these asset files have ZERO BYTES. This includes both the application-<hash>.css and application-<hash.js files, as well as all images.
Another thing I want to point out is that this application is running locally on my docker container, so it has nothing to do with Nginx.
Now this is weird. Here is my staging configuration for reference, any ideas?
# Settings specified here will take precedence over those in config/application.rb
# Configures whether Rails should serve static files from the public directory.
config.public_file_server.enabled = true
# Configures whether all registered config.eager_load_namespaces should be loaded at compile-time. This includes your application, engines, Rails frameworks and any other registered namespace.
config.eager_load = true
# Code is not reloaded between requests
config.cache_classes = true
# Configures whether or not to show helpful development messages on error
config.consider_all_requests_local = false
# Enable fragment caching (https://guides.rubyonrails.org/caching_with_rails.html#fragment-caching)
config.action_controller.perform_caching = true
# Configures Rails itself to serve static files
config.serve_static_files = false
# Compress javascripts and css
config.assets.compress = true
# Specify whether or not to fall back to Sprockets if precompiled assets aren't loaded
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# Send logs to Docker STDOUT
config.logger = Logger.new('/proc/1/fd/1')
# Doesn't actually send mail
config.action_mailer.perform_deliveries = false
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = "X-Sendfile"
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
config.action_mailer.raise_delivery_errors = false
The problem was in the lines:
According to the Official Rails Documentation on x_sendfile_header, this will intercept the body that is being served from a file and replace it with a server specific X-Sendfile header.
Without too much of a dive, this is probably something to do with having Nginx serve the assets instead of Rails, which is not what I'm doing.
Either way, removing this causes the browser to receive files with the content I am expecting it to get from
public/