mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-13 16:34:45 +08:00
parent
7f39c6be76
commit
1fab2f54bf
4 changed files with 27 additions and 0 deletions
|
@ -184,6 +184,9 @@ The following environment variables configure Livebook:
|
||||||
Enabled by default unless `LIVEBOOK_PASSWORD` is set. Set it to "false" to
|
Enabled by default unless `LIVEBOOK_PASSWORD` is set. Set it to "false" to
|
||||||
disable it.
|
disable it.
|
||||||
|
|
||||||
|
* LIVEBOOK_FORCE_SSL_HOST - set a host to redirect to if the request is not over HTTP.
|
||||||
|
Note it does not apply when accessing Livebook via localhost. Defaults to nil.
|
||||||
|
|
||||||
<!-- Environment variables -->
|
<!-- Environment variables -->
|
||||||
|
|
||||||
If running Livebook as a Docker image or an Elixir release, [the environment
|
If running Livebook as a Docker image or an Elixir release, [the environment
|
||||||
|
|
|
@ -58,6 +58,10 @@ defmodule Livebook do
|
||||||
config :livebook, :data_path, data_path
|
config :livebook, :data_path, data_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if force_ssl_host = Livebook.Config.force_ssl_host!("LIVEBOOK_FORCE_SSL_HOST") do
|
||||||
|
config :livebook, :force_ssl_host, force_ssl_host
|
||||||
|
end
|
||||||
|
|
||||||
config :livebook,
|
config :livebook,
|
||||||
:cookie,
|
:cookie,
|
||||||
Livebook.Config.cookie!("LIVEBOOK_COOKIE") ||
|
Livebook.Config.cookie!("LIVEBOOK_COOKIE") ||
|
||||||
|
|
|
@ -197,6 +197,13 @@ defmodule Livebook.Config do
|
||||||
System.get_env(env, "1") in ~w(true 1)
|
System.get_env(env, "1") in ~w(true 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Parses force ssl host setting from env.
|
||||||
|
"""
|
||||||
|
def force_ssl_host!(env) do
|
||||||
|
System.get_env(env)
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Parses and validates default runtime from env.
|
Parses and validates default runtime from env.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -54,6 +54,8 @@ defmodule LivebookWeb.Endpoint do
|
||||||
file_provider: AssetsMemoryProvider,
|
file_provider: AssetsMemoryProvider,
|
||||||
gzip: true
|
gzip: true
|
||||||
|
|
||||||
|
plug :force_ssl
|
||||||
|
|
||||||
# Code reloading can be explicitly enabled under the
|
# Code reloading can be explicitly enabled under the
|
||||||
# :code_reloader configuration of your endpoint.
|
# :code_reloader configuration of your endpoint.
|
||||||
if code_reloading? do
|
if code_reloading? do
|
||||||
|
@ -83,6 +85,17 @@ defmodule LivebookWeb.Endpoint do
|
||||||
|
|
||||||
plug LivebookWeb.Router
|
plug LivebookWeb.Router
|
||||||
|
|
||||||
|
@plug_ssl Plug.SSL.init(host: {Application, :get_env, [:livebook, :force_ssl_host, nil]})
|
||||||
|
def force_ssl(conn, _opts) do
|
||||||
|
force_ssl_host = Application.get_env(:livebook, :force_ssl_host, nil)
|
||||||
|
|
||||||
|
if force_ssl_host do
|
||||||
|
Plug.SSL.call(conn, @plug_ssl)
|
||||||
|
else
|
||||||
|
conn
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def access_struct_url() do
|
def access_struct_url() do
|
||||||
base =
|
base =
|
||||||
case struct_url() do
|
case struct_url() do
|
||||||
|
|
Loading…
Add table
Reference in a new issue