如何将请求转发到 Sinatra 中的不同端点
How to forward request to different endpoint in Sinatra
我有一个端点单独负责所有表单提交;这个端点然后将数据发送到表单提交中的数据给它的正确端点(例如从隐藏字段)。
我知道将数据发送到哪里:
post to /account
如何在不进行重定向的情况下将服务器接收到的数据直接转发到同一服务器上的另一个端点?
或者是使用像 curb 或 rest-client 这样的 HTTP 客户端的唯一方法吗?
它看起来不太好,但你可以尝试这样的事情:
post "/account" do
call! env.merge('PATH_INFO' => "/another/endpoint")
end
post "/another/endpoint" do
...
end
但通常最好提取 /another/endpoint
中的任何代码并直接从 /account
端点调用它。例如:
post "/account" do
process_data(...)
end
post "/another/endpoint" do
process_data(...)
end
def process_data(...)
...
end
我有一个端点单独负责所有表单提交;这个端点然后将数据发送到表单提交中的数据给它的正确端点(例如从隐藏字段)。
我知道将数据发送到哪里:
post to /account
如何在不进行重定向的情况下将服务器接收到的数据直接转发到同一服务器上的另一个端点?
或者是使用像 curb 或 rest-client 这样的 HTTP 客户端的唯一方法吗?
它看起来不太好,但你可以尝试这样的事情:
post "/account" do
call! env.merge('PATH_INFO' => "/another/endpoint")
end
post "/another/endpoint" do
...
end
但通常最好提取 /another/endpoint
中的任何代码并直接从 /account
端点调用它。例如:
post "/account" do
process_data(...)
end
post "/another/endpoint" do
process_data(...)
end
def process_data(...)
...
end