【发布时间】: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为什么不是一个选项?