您不能直接在您的資產文件中配置代理。您必須創建一個config.ru
文件並使用rackup
命令啓動服務器。
下面是一個例子Assetfile:
input "app"
output "public"
而且config.ru:
require 'rake-pipeline'
require 'rake-pipeline/middleware'
require "rack/streaming_proxy" # Don't forget to install the rack-streaming-proxy gem.
use Rack::StreamingProxy do |request|
# Insert your own logic here
if request.path.start_with?("/api")
"http://localhost#{request.path.sub("/api", "")}"
end
end
use Rake::Pipeline::Middleware, 'Assetfile' # This is the path to your Assetfile
run Rack::Directory.new('public') # This should match whatever your Assetfile's output directory is
你必須安裝機架和機架流代理的寶石。
謝謝托馬斯,你能再詳細一點嗎?我有一個像這樣的資產文件https://gist.github.com/1608930我在哪裏添加Rack :: Proxy代碼? – 2012-01-13 21:59:14
這是如何傳遞方法,POST,DELETE或PUT的?它看起來像只是將每個方法轉換爲GET。 – Lucas 2012-09-06 22:20:56