mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-02-25 23:52:31 +08:00
Move to Bandit (#2316)
This commit is contained in:
parent
0e06d8c0e7
commit
6ec335fce5
12 changed files with 32 additions and 26 deletions
|
@ -2,6 +2,7 @@ import Config
|
|||
|
||||
# Configures the endpoint
|
||||
config :livebook, LivebookWeb.Endpoint,
|
||||
adapter: Bandit.PhoenixAdapter,
|
||||
url: [host: "localhost", path: "/"],
|
||||
pubsub_server: Livebook.PubSub,
|
||||
live_view: [signing_salt: "livebook"],
|
||||
|
@ -22,9 +23,6 @@ config :mime, :types, %{
|
|||
"text/plain" => ["livemd"]
|
||||
}
|
||||
|
||||
# We want CSRF tokens to be logged to help users with debugging
|
||||
config :plug_cowboy, :log_exceptions_with_status_code, [407..599]
|
||||
|
||||
config :livebook,
|
||||
teams_url: "https://teams.livebook.dev",
|
||||
app_service_name: nil,
|
||||
|
|
|
@ -8,7 +8,12 @@ import Config
|
|||
config :livebook, LivebookWeb.Endpoint,
|
||||
# Binding to loopback ipv4 address prevents access from other machines.
|
||||
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
|
||||
http: [ip: {127, 0, 0, 1}, port: 4000, protocol_options: [max_header_value_length: 32768]],
|
||||
http: [
|
||||
ip: {127, 0, 0, 1},
|
||||
port: 4000,
|
||||
http_1_options: [max_header_length: 32768],
|
||||
http_2_options: [max_header_value_length: 32768]
|
||||
],
|
||||
code_reloader: true,
|
||||
debug_errors: true,
|
||||
check_origin: false,
|
||||
|
|
|
@ -2,7 +2,12 @@ import Config
|
|||
|
||||
# Default bind and port for production
|
||||
config :livebook, LivebookWeb.Endpoint,
|
||||
http: [ip: {127, 0, 0, 1}, port: 8080, protocol_options: [max_header_value_length: 32768]],
|
||||
http: [
|
||||
ip: {127, 0, 0, 1},
|
||||
port: 8080,
|
||||
http_1_options: [max_header_length: 32768],
|
||||
http_2_options: [max_header_value_length: 32768]
|
||||
],
|
||||
server: true
|
||||
|
||||
config :livebook, :iframe_port, 8081
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
defmodule LivebookSpace.Application do
|
||||
|
||||
use Application
|
||||
|
||||
def start(_type, _args) do
|
||||
children = [
|
||||
{Plug.Cowboy, scheme: :http, plug: LivebookSpaceWeb.Plug, options: [port: 4000]}
|
||||
{Bandit, scheme: :http, plug: LivebookSpaceWeb.Plug, port: 4000}
|
||||
]
|
||||
|
||||
opts = [strategy: :one_for_one, name: LivebookSpace.Supervisor]
|
||||
|
|
|
@ -20,7 +20,7 @@ defmodule LivebookSpace.MixProject do
|
|||
|
||||
defp deps do
|
||||
[
|
||||
{:plug_cowboy, "~> 2.0"}
|
||||
{:bandit, "~> 1.0"}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
%{
|
||||
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
|
||||
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
|
||||
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
|
||||
"bandit": {:hex, :bandit, "1.0.0", "2bd87bbf713d0eed0090f2fa162cd1676198122e6c2b68a201c706e354a6d5e5", [:mix], [{:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "32acf6ac030fee1f99fd9c3fcf81671911ae8637e0a61c98111861b466efafdb"},
|
||||
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
|
||||
"mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"},
|
||||
"plug": {:hex, :plug, "1.13.2", "33aba8e2b43ddd68d9d49b818ed2fb46da85f4ec3229bc4bcd0c981a640a4e71", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a95cdfe599e3524b98684376c3f3494cbfbc1f41fcddefc380cac3138dd7619d"},
|
||||
"plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"},
|
||||
"plug": {:hex, :plug, "1.15.1", "b7efd81c1a1286f13efb3f769de343236bd8b7d23b4a9f40d3002fc39ad8f74c", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "459497bd94d041d98d948054ec6c0b76feacd28eec38b219ca04c0de13c79d30"},
|
||||
"plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"},
|
||||
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
|
||||
"telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"},
|
||||
"thousand_island": {:hex, :thousand_island, "1.1.0", "dcc115650adc61c5e7de12619f0cb94b2b8f050326e7f21ffbf6fdeb3d291e4c", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7745cf71520d74e119827ff32c2da6307e822cf835bebed3b2c459cc57f32d21"},
|
||||
"websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"},
|
||||
}
|
||||
|
|
|
@ -363,7 +363,7 @@ defmodule Livebook.Application do
|
|||
port: port
|
||||
] ++ Keyword.take(http, [:ip])
|
||||
|
||||
spec = Plug.Cowboy.child_spec(iframe_opts)
|
||||
spec = Bandit.child_spec(iframe_opts)
|
||||
spec = update_in(spec.start, &{__MODULE__, :start_iframe, [port, &1]})
|
||||
[spec]
|
||||
else
|
||||
|
|
|
@ -617,14 +617,15 @@ defmodule Livebook.Utils do
|
|||
The listener references usually follow the pattern `plug.HTTP`
|
||||
and `plug.HTTPS`.
|
||||
"""
|
||||
@spec get_port(:ranch.ref(), :inet.port_number()) :: :inet.port_number()
|
||||
def get_port(ref, default) do
|
||||
@spec get_port(module, :http | :https, :inet.port_number()) :: :inet.port_number()
|
||||
def get_port(endpoint, scheme, default) do
|
||||
try do
|
||||
:ranch.get_addr(ref)
|
||||
{:ok, pid} = Bandit.PhoenixAdapter.bandit_pid(endpoint, scheme)
|
||||
ThousandIsland.listener_info(pid)
|
||||
rescue
|
||||
_ -> default
|
||||
else
|
||||
{_, port} when is_integer(port) -> port
|
||||
{:ok, {_, port}} when is_integer(port) -> port
|
||||
_ -> default
|
||||
end
|
||||
end
|
||||
|
|
|
@ -140,10 +140,10 @@ defmodule LivebookWeb.Endpoint do
|
|||
base =
|
||||
case struct_url() do
|
||||
%URI{scheme: "https", port: 0} = uri ->
|
||||
%{uri | port: Livebook.Utils.get_port(__MODULE__.HTTPS, 433)}
|
||||
%{uri | port: Livebook.Utils.get_port(__MODULE__, :https, 433)}
|
||||
|
||||
%URI{scheme: "http", port: 0} = uri ->
|
||||
%{uri | port: Livebook.Utils.get_port(__MODULE__.HTTP, 80)}
|
||||
%{uri | port: Livebook.Utils.get_port(__MODULE__, :http, 80)}
|
||||
|
||||
%URI{} = uri ->
|
||||
uri
|
||||
|
|
|
@ -35,7 +35,7 @@ defmodule LivebookWeb.IframeEndpoint do
|
|||
iframe_port = Livebook.Config.iframe_port()
|
||||
|
||||
case livebook_port do
|
||||
0 -> Livebook.Utils.get_port(__MODULE__.HTTP, iframe_port)
|
||||
0 -> Livebook.Utils.get_port(__MODULE__, :http, iframe_port)
|
||||
_ -> iframe_port
|
||||
end
|
||||
end
|
||||
|
|
3
mix.exs
3
mix.exs
|
@ -102,7 +102,7 @@ defmodule Livebook.MixProject do
|
|||
{:telemetry_metrics, "~> 0.4"},
|
||||
{:telemetry_poller, "~> 1.0"},
|
||||
{:jason, "~> 1.0"},
|
||||
{:plug_cowboy, "~> 2.0"},
|
||||
{:bandit, "~> 1.0"},
|
||||
{:plug_crypto, "~> 2.0"},
|
||||
{:earmark_parser, "~> 1.4"},
|
||||
{:castore, "~> 1.0"},
|
||||
|
@ -118,7 +118,6 @@ defmodule Livebook.MixProject do
|
|||
# ZTA deps
|
||||
{:jose, "~> 1.11.5"},
|
||||
{:req, "~> 0.4.4"},
|
||||
{:bandit, "~> 0.7", only: :test},
|
||||
# Docs
|
||||
{:ex_doc, "~> 0.30", only: :dev, runtime: false}
|
||||
]
|
||||
|
|
4
mix.lock
4
mix.lock
|
@ -1,6 +1,6 @@
|
|||
%{
|
||||
"aws_signature": {:hex, :aws_signature, "0.3.1", "67f369094cbd55ffa2bbd8cc713ede14b195fcfb45c86665cd7c5ad010276148", [:rebar3], [], "hexpm", "50fc4dc1d1f7c2d0a8c63f455b3c66ecd74c1cf4c915c768a636f9227704a674"},
|
||||
"bandit": {:hex, :bandit, "0.7.7", "48456d09022607a312cf723a91992236aeaffe4af50615e6e2d2e383fb6bef10", [:mix], [{:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 0.6.7", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "772f0a32632c2ce41026d85e24b13a469151bb8cea1891e597fb38fde103640a"},
|
||||
"bandit": {:hex, :bandit, "1.0.0", "2bd87bbf713d0eed0090f2fa162cd1676198122e6c2b68a201c706e354a6d5e5", [:mix], [{:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "32acf6ac030fee1f99fd9c3fcf81671911ae8637e0a61c98111861b466efafdb"},
|
||||
"bypass": {:hex, :bypass, "2.1.0", "909782781bf8e20ee86a9cabde36b259d44af8b9f38756173e8f5e2e1fabb9b1", [:mix], [{:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "d9b5df8fa5b7a6efa08384e9bbecfe4ce61c77d28a4282f79e02f1ef78d96b80"},
|
||||
"castore": {:hex, :castore, "1.0.4", "ff4d0fb2e6411c0479b1d965a814ea6d00e51eb2f58697446e9c41a97d940b28", [:mix], [], "hexpm", "9418c1b8144e11656f0be99943db4caf04612e3eaecefb5dae9a2a87565584f8"},
|
||||
"cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"},
|
||||
|
@ -43,7 +43,7 @@
|
|||
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
|
||||
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"},
|
||||
"telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"},
|
||||
"thousand_island": {:hex, :thousand_island, "0.6.7", "3a91a7e362ca407036c6691e8a4f6e01ac8e901db3598875863a149279ac8571", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "541a5cb26b88adf8d8180b6b96a90f09566b4aad7a6b3608dcac969648cf6765"},
|
||||
"thousand_island": {:hex, :thousand_island, "1.1.0", "dcc115650adc61c5e7de12619f0cb94b2b8f050326e7f21ffbf6fdeb3d291e4c", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7745cf71520d74e119827ff32c2da6307e822cf835bebed3b2c459cc57f32d21"},
|
||||
"websock": {:hex, :websock, "0.5.1", "c496036ce95bc26d08ba086b2a827b212c67e7cabaa1c06473cd26b40ed8cf10", [:mix], [], "hexpm", "b9f785108b81cd457b06e5f5dabe5f65453d86a99118b2c0a515e1e296dc2d2c"},
|
||||
"websock_adapter": {:hex, :websock_adapter, "0.5.4", "7af8408e7ed9d56578539594d1ee7d8461e2dd5c3f57b0f2a5352d610ddde757", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "d2c238c79c52cbe223fcdae22ca0bb5007a735b9e933870e241fce66afb4f4ab"},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue