【问题标题】:Setting the :public_folder per route in Sinatra?在 Sinatra 中为每条路线设置 :public_folder?
【发布时间】:2013-09-25 07:08:49
【问题描述】:

我需要为 Sinatra 提供多个单独的 angularjs 应用程序。是的,这些应该从 HTTP 服务器提供,但这不是一个选项。

这是我的目录设置(出于示例目的而精简)

/SinatraApp
|--  public
|    |--  App1
|    |    |--  scripts
|    |    |--  styles
|    |    |--  index.html
|    |--  App2
|    |    |--  scripts
|    |    |--  styles
|    |    |--  index.html
|--  app.rb

我先试了

set :public_folder, 'public'

然后分别在每个索引路由中

get '/App1' do
  send_file File.join(settings.public_folder, 'App1', 'index.html')
end
get '/App2' do
  send_file File.join(settings.public_folder, 'App2', 'index.html')
end

但这不起作用。它可以很好地为 index.html 文件提供服务,但资产链接到 localhost/scripts 而不是 localhost/App1/scripts。然后我尝试为每条路线设置 :public_folder 设置。没有运气。

get '/App1' do
  set :public_folder, File.join('public', 'App1')
  send_file File.join(settings.public_folder, 'index.html')
end

我得到这个错误:

NoMethodError at /App1
undefined method `set' for #<Sinatra::Application:0x2548ba8>
file: app.rb location: block in <main> line: 73

我真的很想避免为另一个 Angular 应用程序生成另一个 Sinatra 应用程序,我真的需要它来工作。想法?

【问题讨论】:

  • Yes, these should be served from a HTTP server but that is not an option 为什么不是一个选项?

标签: angularjs sinatra


【解决方案1】:

为此找到了解决方案。 Sinatra 中的模块应用程序与 config.ru 文件的组合。 http://titusd.co.uk/2010/04/07/a-beginners-sinatra-tutorial/

【讨论】:

    猜你喜欢
    • 2013-12-23
    • 1970-01-01
    • 2021-04-29
    • 2019-12-06
    • 1970-01-01
    • 1970-01-01
    • 2019-12-09
    • 2011-07-02
    • 1970-01-01
    相关资源
    最近更新 更多