4

WebPart指定した別の Web サーバーにすべての要求を転送する を作成したいと考えています。

使用法は次のようになります。

let app = 
  choose
    [
      path "/" >=> OK "Hello, world. "
      path "/graphql" >=> createProxy "localhost:5000"
      RequestErrors.NOT_FOUND "Not found"
    ]

startWebServer defaultConfig app

これを Suave でどのように実装すればよいですか?


このスニペットを見つけましたが、古いバージョンの Suave 用のようです:

let build_proxy_resolver (fwd_to_host : String) fwd_to_port = 
  let heserver = System.Net.Dns.GetHostEntry(fwd_to_host)
  let ipaddr = heserver.AddressList.[0]
  fun (request : HttpRequest) ->
    Some (ipaddr, fwd_to_port)

let build_headers ctx =
  //add and remove headers from the ctx, return the header list
  ctx.request.headers

let proxy_app (ctx:HttpContext) = 
  let new_headers = build_headers ctx
  let fwd_ctx = {ctx with request={ctx.request with headers=new_headers}}
  let pxy = proxy (build_proxy_resolver "PROXY_TO.com" 80us) fwd_ctx
  {ctx with response = { ctx.response with status=Suave.Types.Codes.HTTP_200; content=SocketTask pxy }} |> Some
4

1 に答える 1