【问题标题】:Public Directory Not Being Served With SinatraSinatra 未提供公共目录
【发布时间】:2017-08-20 17:17:29
【问题描述】:

正如标题所说,我无法让 Heroku 使用我的公共资产。

在本地,当使用shotgun 运行我的应用程序时,它可以工作。但是使用rackup(Heroku 使用的),css 和资产 404。

我在这里尝试了很多答案(onetwothree),但都没有奏效。

这是我的目录结构:

我的 config.ru:

require 'bundler'
Bundler.require

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

run BikeShareApp

还有我的控制器:

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

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

编辑:顺便说一句,这就是我引用我的资产的方式

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

【问题讨论】:

    标签: heroku sinatra rackup


    【解决方案1】:

    找到了。

    按照this 指南并将其放入我的 config.ru 工作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-28
      • 2020-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多