2017-12-08 08:58:14 +00:00
|
|
|
defmodule EventosWeb.Endpoint do
|
2018-01-14 16:56:50 +00:00
|
|
|
@moduledoc """
|
|
|
|
Endpoint for Eventos app
|
|
|
|
"""
|
2017-12-08 08:58:14 +00:00
|
|
|
use Phoenix.Endpoint, otp_app: :eventos
|
|
|
|
|
2018-07-27 08:45:35 +00:00
|
|
|
socket("/socket", EventosWeb.UserSocket)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
|
|
|
# Serve at "/" the static files from "priv/static" directory.
|
|
|
|
#
|
|
|
|
# You should set gzip to true if you are running phoenix.digest
|
|
|
|
# when deploying your static files in production.
|
2018-07-27 08:45:35 +00:00
|
|
|
plug(
|
|
|
|
Plug.Static,
|
|
|
|
at: "/",
|
|
|
|
from: :eventos,
|
|
|
|
gzip: false,
|
2018-01-09 16:52:26 +00:00
|
|
|
only: ~w(css fonts images js favicon.ico robots.txt index.html)
|
2018-07-27 08:45:35 +00:00
|
|
|
)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
|
|
|
# Code reloading can be explicitly enabled under the
|
|
|
|
# :code_reloader configuration of your endpoint.
|
|
|
|
if code_reloading? do
|
2018-07-27 08:45:35 +00:00
|
|
|
socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
|
|
|
|
plug(Phoenix.LiveReloader)
|
|
|
|
plug(Phoenix.CodeReloader)
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|
|
|
|
|
2018-07-27 08:45:35 +00:00
|
|
|
plug(CORSPlug)
|
|
|
|
plug(Plug.RequestId)
|
|
|
|
plug(Plug.Logger)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
2018-07-27 08:45:35 +00:00
|
|
|
plug(
|
|
|
|
Plug.Parsers,
|
2017-12-08 08:58:14 +00:00
|
|
|
parsers: [:urlencoded, :multipart, :json],
|
|
|
|
pass: ["*/*"],
|
|
|
|
json_decoder: Poison
|
2018-07-27 08:45:35 +00:00
|
|
|
)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
2018-07-27 08:45:35 +00:00
|
|
|
plug(Plug.MethodOverride)
|
|
|
|
plug(Plug.Head)
|
2017-12-08 08:58:14 +00: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.
|
2018-07-27 08:45:35 +00:00
|
|
|
plug(
|
|
|
|
Plug.Session,
|
2017-12-08 08:58:14 +00:00
|
|
|
store: :cookie,
|
|
|
|
key: "_eventos_key",
|
|
|
|
signing_salt: "F9CCTF22"
|
2018-07-27 08:45:35 +00:00
|
|
|
)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
2018-07-27 08:45:35 +00:00
|
|
|
plug(EventosWeb.Router)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Callback invoked for dynamically configuring the endpoint.
|
|
|
|
|
|
|
|
It receives the endpoint configuration and checks if
|
|
|
|
configuration should be loaded from the system environment.
|
|
|
|
"""
|
|
|
|
def init(_key, config) do
|
|
|
|
if config[:load_from_system_env] do
|
|
|
|
port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
|
|
|
|
{:ok, Keyword.put(config, :http, [:inet6, port: port])}
|
|
|
|
else
|
|
|
|
{:ok, config}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|