rake-pipeline - 使用 rake-pipeline-web-filters 代理 ajax 调用

标签 rake-pipeline

我正在使用 rake-pipeline 为 Ember.js 应用程序设置开发环境,如 here 中所述。 。

在开发过程中,我的 html 和 javascript 由 http://0.0.0.0:9292 上的 webrick(我不太理解的 rake-filter 魔法)提供服务,并且我有一个 REST 服务使用 Apache 在 http://somename.local

上提供的 php 开发

由于浏览器的反跨域 ajax 功能,我从客户端应用程序发出的 ajax 调用丢失了。我该如何解决这个问题?

最佳答案

您无法直接在 Assets 文件中配置代理。您必须创建一个 config.ru 文件并使用 rackup 命令启动服务器。

这是一个示例资源文件:

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

您必须安装rack 和rack-streaming-proxy gem。

关于rake-pipeline - 使用 rake-pipeline-web-filters 代理 ajax 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8810118/

相关文章:

rake 式管道性能