Sam Lim
Sam Lim

Reputation: 197

Public Directory Not Being Served With Sinatra

As the title says, I cannot get Heroku to use my public assets.

Locally, when running my app with shotgun it works. But with rackup (what Heroku uses), the css and assets 404.

I've tried a bunch of answers on here (one, two, three) but none have worked.

Here's my directory structure:

dir struct

My config.ru:

require 'bundler'
Bundler.require

require File.expand_path('../config/environment',  __FILE__)

run BikeShareApp

And my controller:

class BikeShareApp < Sinatra::Base
  get '/' do
    erb :'home/index'
  end

  get '/stations' do
    @stations = Station.all
    erb :'stations/index'
  end
end

EDIT: This is how I'm referencing my assets by the way

<link href="/css/bootstrap.min.css" rel="stylesheet">
<link href="/css/overwrite.css" rel="stylesheet">

Upvotes: 0

Views: 54

Answers (1)

Sam Lim
Sam Lim

Reputation: 197

Found it.

Following this guide and putting this in my config.ru worked:

run lambda { |env|
  [
    200,
    {
      'Content-Type'  => 'text/html',
      'Cache-Control' => 'public, max-age=86400'
    }
  ]
}

Upvotes: 0

Related Questions