/
phoenix.ex
88 lines (66 loc) · 2.74 KB
/
phoenix.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
defmodule Phoenix do
@moduledoc """
This is the documentation for the Phoenix project.
By default, Phoenix applications depend on the following packages:
* [Ecto](https://hexdocs.pm/ecto) - a language integrated query and
database wrapper
* [Phoenix](https://hexdocs.pm/phoenix) - the Phoenix web framework
(these docs)
* [Phoenix.js](js) - Phoenix Channels JavaScript client
* [Phoenix PubSub](https://hexdocs.pm/phoenix_pubsub) - a distributed
pub/sub system with presence support
* [Phoenix HTML](https://hexdocs.pm/phoenix_html) - conveniences for
working with HTML in Phoenix
* [Plug](https://hexdocs.pm/plug) - a specification and conveniences
for composable modules in between web applications
* [Gettext](https://hexdocs.pm/gettext) - Internationalization and
localization through [`gettext`](https://www.gnu.org/software/gettext/)
There are also optional packages depending on your configuration:
* [Phoenix PubSub Redis](https://hexdocs.pm/phoenix_pubsub_redis) - use
Redis to power the Phoenix PubSub system
"""
use Application
@doc false
def start(_type, _args) do
# Warm up caches
_ = Phoenix.Template.engines()
_ = Phoenix.Template.format_encoder("index.html")
warn_on_missing_format_encoders()
# Configure proper system flags from Phoenix only
if stacktrace_depth = Application.get_env(:phoenix, :stacktrace_depth) do
:erlang.system_flag(:backtrace_depth, stacktrace_depth)
end
# Start the supervision tree
import Supervisor.Spec
children = [
# Code reloading must be serial across all Phoenix apps
worker(Phoenix.CodeReloader.Server, [])
]
Supervisor.start_link(children, strategy: :one_for_one, name: Phoenix.Supervisor)
end
# TODO: swap Poison default with Jason in 2.0
# from there we can ditch explicit config for new projects
@doc """
Returns the configured JSON encoding library for Phoenix.
To customize the JSON library, including the following
in your `config/config.exs`:
config :phoenix, :json_library, Jason
"""
def json_library do
case Application.fetch_env(:phoenix, :json_library) do
{:ok, module} -> module
:error -> Poison
end
end
defp warn_on_missing_format_encoders do
for {format, mod} <- Application.fetch_env!(:phoenix, :format_encoders) do
Code.ensure_loaded?(mod) || IO.write :sterr, """
failed to load #{inspect(mod)} for Phoenix :#{format} encoder
(module #{inspect(mod)} is not available)
Ensure #{inspect(mod)} is loaded from your deps in mix.exs, or
configure an existing encoder in your mix config using:
config :phoenix, :format_encoders, #{format}: MyEncoder
"""
end
end
end