till commented on issue #4656:
URL: https://github.com/apache/couchdb/issues/4656#issuecomment-2746152088

   Here are examples in Elixir (I am sadly not profficient in Erlang) and Go 
which both work. They bind on `0.0.0.0:31337` and the `curl` command works with 
either.
   
   ```elixir
   Mix.install([:plug_cowboy])
   
   defmodule EchoServer do
     use Plug.Router
   
     plug :match
     plug :dispatch
   
     get "/" do
       headers = conn.req_headers |> Enum.map_join("\n", fn {k, v} -> "#{k}: 
#{v}" end)
       send_resp(conn, 200, headers)
     end
   
     match _ do
       send_resp(conn, 404, "Not Found")
     end
   end
   
   {:ok, _} = Plug.Cowboy.http(EchoServer, [], ip: {0, 0, 0, 0}, port: 31337)
   
   IO.puts("Echo server running on http://0.0.0.0:31337";)
   
   Process.sleep(:infinity)
   ```
   
   Here is my example in Go:
   
   ```go
   package main
   
   import (
        "encoding/json"
        "fmt"
        "net/http"
        "os"
   )
   
   func main() {
   
        http.HandleFunc("/", respond)
        if err := http.ListenAndServe("0.0.0.0:31337", nil); err != nil {
                fmt.Println("err:", err)
                os.Exit(1)
        }
        os.Exit(0)
   }
   
   func respond(w http.ResponseWriter, r *http.Request) {
        w.Header().Set("Content-Type", "application/json")
        w.WriteHeader(http.StatusOK)
   
        json.NewEncoder(w).Encode(map[string]any{
                "header": r.Header,
        })
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to