ibpix
ibpix

Reputation: 319

serving static files on sinatra

I'm working on a Sinatra app for the first time and am stumbling into an issue with serving a javascript asset.

I am following the Sinatra convention of putting the static files in “public” folder and it works locally but when we create a Docker image, we get a 404 while this works with localhost.

I see where I can set the public_folder which I have tried like this: http://sinatrarb.com/configuration.html

but still 404'ing. Is there a way to get the top-level object and ask it where it expects the public_folder to be (like Rails.env)?

Upvotes: 1

Views: 301

Answers (1)

Sir l33tname
Sir l33tname

Reputation: 4330

You can check the settings object.

irb(main):001:0> require "sinatra"
=> true
irb(main):002:0> settings.public_folder
=> "/usr/lib/ruby/2.5.0/irb/public"

This allows you to create a route which returns the path, something like this

require 'sinatra'

get '/' do
    settings.public_folder
end

Without more information I would guess that your public folder points to a wrong directory inside your docker because the project :root points to a different directory that what you expect.

Upvotes: 2

Related Questions