2021-03-04 05:56:28 +08:00
|
|
|
defmodule LivebookWeb.Endpoint do
|
|
|
|
use Phoenix.Endpoint, otp_app: :livebook
|
2021-01-08 03:55:45 +08:00
|
|
|
|
|
|
|
# The session will be stored in the cookie and signed,
|
|
|
|
# this means its contents can be read but not tampered with.
|
|
|
|
# Set :encryption_salt if you would also like to encrypt it.
|
|
|
|
@session_options [
|
|
|
|
store: :cookie,
|
2021-03-04 05:56:28 +08:00
|
|
|
key: "_livebook_key",
|
2021-01-08 04:16:54 +08:00
|
|
|
signing_salt: "SqUy8vWM"
|
2021-01-08 03:55:45 +08:00
|
|
|
]
|
|
|
|
|
2021-02-18 20:14:09 +08:00
|
|
|
socket "/live", Phoenix.LiveView.Socket,
|
2021-03-17 18:16:40 +08:00
|
|
|
# Don't check the origin as we don't know how the web app is gonna be accessed.
|
|
|
|
# It runs locally, but may be exposed via IP or domain name.
|
|
|
|
# The WebSocket connection is already protected from CSWSH by using CSRF token.
|
|
|
|
websocket: [check_origin: false, connect_info: [:user_agent, session: @session_options]]
|
2021-01-08 04:16:54 +08:00
|
|
|
|
2021-03-17 08:53:44 +08:00
|
|
|
# We use Escript for distributing Livebook, so we don't
|
|
|
|
# have access to the files in priv/static at runtime in the prod environment.
|
|
|
|
# To overcome this we load contents of those files at compilation time,
|
|
|
|
# so that they become a part of the executable and can be served
|
|
|
|
# from memory.
|
|
|
|
defmodule AssetsMemoryProvider do
|
|
|
|
use LivebookWeb.MemoryProvider,
|
|
|
|
from: :livebook,
|
|
|
|
gzip: true
|
|
|
|
end
|
|
|
|
|
|
|
|
defmodule AssetsFileSystemProvider do
|
|
|
|
use LivebookWeb.FileSystemProvider,
|
|
|
|
from: {:livebook, "priv/static_dev"}
|
|
|
|
end
|
|
|
|
|
|
|
|
file_provider = if(Mix.env() == :prod, do: AssetsMemoryProvider, else: AssetsFileSystemProvider)
|
|
|
|
|
|
|
|
# Serve static failes at "/"
|
|
|
|
plug LivebookWeb.StaticPlug,
|
2021-01-08 03:55:45 +08:00
|
|
|
at: "/",
|
2021-03-17 08:53:44 +08:00
|
|
|
file_provider: file_provider,
|
|
|
|
gzip: true
|
2021-01-08 03:55:45 +08:00
|
|
|
|
|
|
|
# Code reloading can be explicitly enabled under the
|
|
|
|
# :code_reloader configuration of your endpoint.
|
|
|
|
if code_reloading? do
|
|
|
|
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
|
|
|
|
plug Phoenix.LiveReloader
|
|
|
|
plug Phoenix.CodeReloader
|
|
|
|
end
|
|
|
|
|
|
|
|
plug Plug.RequestId
|
|
|
|
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
|
|
|
|
|
|
|
|
plug Plug.Parsers,
|
|
|
|
parsers: [:urlencoded, :multipart, :json],
|
|
|
|
pass: ["*/*"],
|
|
|
|
json_decoder: Phoenix.json_library()
|
|
|
|
|
|
|
|
plug Plug.MethodOverride
|
|
|
|
plug Plug.Head
|
|
|
|
plug Plug.Session, @session_options
|
2021-03-04 05:56:28 +08:00
|
|
|
plug LivebookWeb.Router
|
2021-01-08 03:55:45 +08:00
|
|
|
end
|