endpoint.ex 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. defmodule WebWeb.Endpoint do
  2. use Phoenix.Endpoint, otp_app: :web
  3. socket "/socket", WebWeb.UserSocket
  4. # Serve at "/" the static files from "priv/static" directory.
  5. #
  6. # You should set gzip to true if you are running phoenix.digest
  7. # when deploying your static files in production.
  8. plug Plug.Static,
  9. at: "/", from: :web, gzip: false,
  10. only: ~w(css fonts images js favicon.ico robots.txt)
  11. # Code reloading can be explicitly enabled under the
  12. # :code_reloader configuration of your endpoint.
  13. if code_reloading? do
  14. socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
  15. plug Phoenix.LiveReloader
  16. plug Phoenix.CodeReloader
  17. end
  18. plug Plug.RequestId
  19. plug Plug.Logger
  20. plug Plug.Parsers,
  21. parsers: [:urlencoded, :multipart, :json],
  22. pass: ["*/*"],
  23. json_decoder: Poison
  24. plug Plug.MethodOverride
  25. plug Plug.Head
  26. # The session will be stored in the cookie and signed,
  27. # this means its contents can be read but not tampered with.
  28. # Set :encryption_salt if you would also like to encrypt it.
  29. plug Plug.Session,
  30. store: :cookie,
  31. key: "_web_key",
  32. signing_salt: "0qUvGOac"
  33. plug WebWeb.Router
  34. @doc """
  35. Callback invoked for dynamically configuring the endpoint.
  36. It receives the endpoint configuration and checks if
  37. configuration should be loaded from the system environment.
  38. """
  39. def init(_key, config) do
  40. if config[:load_from_system_env] do
  41. port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
  42. {:ok, Keyword.put(config, :http, [:inet6, port: port])}
  43. else
  44. {:ok, config}
  45. end
  46. end
  47. end