Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kino.Proxy module #431

Merged
merged 10 commits into from
May 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/kino/proxy.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule Kino.Proxy do
@moduledoc """
A kino for handling proxy requests from the host.
jonatanklosko marked this conversation as resolved.
Show resolved Hide resolved

## Examples

Kino.Proxy.listen(fn conn ->
conn
|> Plug.Conn.put_resp_header("content-type", "application/text;charset=utf-8")
|> Plug.Conn.send_resp(200, "used " <> conn.method <> " method")
end)
"""

@doc """
Persists the function to be listened by the proxy handler.
"""
@spec listen(atom(), module(), (Plug.Conn.t() -> Plug.Conn.t())) ::
DynamicSupervisor.on_start_child()
def listen(name \\ __MODULE__, mod \\ Livebook.Proxy.Handler, fun) when is_function(fun, 1) do
aleDsz marked this conversation as resolved.
Show resolved Hide resolved
Kino.start_child({mod, name: name, listen: fun})
end
end
Loading