Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example app to phoenix 1.5 #254

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/simple/.formatter.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
inputs: [
"{mix,.formatter}.exs",
"{config,lib,test}/**/*.{ex,exs}"
]
import_deps: [:ecto, :phoenix],
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"]
]
38 changes: 25 additions & 13 deletions examples/simple/.gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
# App artifacts
/_build
/db
/deps
/*.ez
# The directory Mix will write compiled artifacts to.
/_build/

# Generated on crash by the VM
# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# The config/prod.secret.exs file by default contains sensitive
# data and you should not commit it into version control.
#
# Alternatively, you may comment the line below and commit the
# secrets file as long as you replace its contents by environment
# variables.
/config/prod.secret.exs
# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
simple-*.tar

# Since we are building assets from assets/,
# we ignore priv/static. You may want to comment
# this depending on your deployment strategy.
/priv/static/
23 changes: 15 additions & 8 deletions examples/simple/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,36 @@
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
use Mix.Config

# General application configuration
use Mix.Config

config :simple,
ecto_repos: [Simple.Repo]

# Configures the endpoint
config :simple, SimpleWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "zF/nkuOvpNhuSI/bBYTk6GCv+CvEZLZ9rjO/XeOaEAnG/YkCWtXVcZG3XsoTXs2q",
render_errors: [view: SimpleWeb.ErrorView, accepts: ~w(json), layout: false],
pubsub_server: Simple.PubSub,
live_view: [signing_salt: "/Bz8Xixi"]

config :simple, :phoenix_swagger,
swagger_files: %{
"priv/static/swagger.json" => [router: SimpleWeb.Router]
}

# Configures the endpoint
config :simple, SimpleWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "occcf4JQ1yY8UbMxsqJx0+wxhrQFQMvAJi+mYlaWCSJxmmrgGLyt4eZ9oFhrisRP",
render_errors: [view: SimpleWeb.ErrorView, accepts: ~w(json)],
pubsub: [name: Simple.PubSub, adapter: Phoenix.PubSub.PG2]

# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id]

# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason

config :phoenix_swagger, json_library: Jason

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"
57 changes: 37 additions & 20 deletions examples/simple/config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
use Mix.Config

# Configure your database
config :simple, Simple.Repo,
username: "postgres",
password: "postgres",
database: "simple_dev",
hostname: "localhost",
show_sensitive_data_on_connection_error: true,
pool_size: 10

# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with brunch.io to recompile .js and .css sources.
# with webpack to recompile .js and .css sources.
config :simple, SimpleWeb.Endpoint,
http: [port: 4000],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [],
live_reload: [
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg|json)$},
~r{priv/gettext/.*(po)$},
~r{lib/simple_web/views/.*(ex)$},
~r{lib/simple_web/controllers/.*(ex)$},
~r{lib/simple_web/templates/.*(eex)$}
]
],
reloadable_compilers: [:gettext, :phoenix, :elixir, :phoenix_swagger]
watchers: []

# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
# certificate can be generated by running the following
# Mix task:
#
# mix phx.gen.cert
#
# Note that this task requires Erlang/OTP 20 or later.
# Run `mix help phx.gen.cert` for more information.
#
# The `http:` config above can be replaced with:
#
# https: [
# port: 4001,
# cipher_suite: :strong,
# keyfile: "priv/cert/selfsigned_key.pem",
# certfile: "priv/cert/selfsigned.pem"
# ],
#
# If desired, both `http:` and `https:` keys can be
# configured to run both http and https servers on
# different ports.

# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"
Expand All @@ -30,11 +53,5 @@ config :logger, :console, format: "[$level] $message\n"
# in production as building large stacktraces may be expensive.
config :phoenix, :stacktrace_depth, 20

# Configure your database
config :simple, Simple.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "simple_dev",
hostname: "localhost",
pool_size: 10
# Initialize plugs at runtime for faster development compilation
config :phoenix, :plug_init_mode, :runtime
85 changes: 34 additions & 51 deletions examples/simple/config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,72 +1,55 @@
use Mix.Config

# For production, we configure the host to read the PORT
# from the system environment. Therefore, you will need
# to set PORT=80 before running your server.
# For production, don't forget to configure the url host
# to something meaningful, Phoenix uses this information
# when generating URLs.
#
# You should also configure the url host to something
# meaningful, we use this information when generating URLs.
#
# Finally, we also include the path to a manifest
# Note we also include the path to a cache manifest
# containing the digested version of static files. This
# manifest is generated by the mix phoenix.digest task
# which you typically run after static files are built.
# manifest is generated by the `mix phx.digest` task,
# which you should run after static files are built and
# before starting your production server.
config :simple, SimpleWeb.Endpoint,
load_from_system_env: true,
url: [host: "example.com", port: 80],
cache_static_manifest: "priv/static/cache_manifest.json"

# Do not print debug messages in production
config :logger, level: :info

config :simple, Simple.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "simple_prod",
hostname: "localhost",
pool_size: 10

# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
# to the previous section and set your `:url` port to 443:
#
# config :simple, Simple.Endpoint,
# config :simple, SimpleWeb.Endpoint,
# ...
# url: [host: "example.com", port: 443],
# https: [port: 443,
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")]
#
# Where those two env variables return an absolute path to
# the key and cert in disk or a relative path inside priv,
# for example "priv/ssl/server.key".
#
# We also recommend setting `force_ssl`, ensuring no data is
# ever sent via http, always redirecting to https:
#
# config :simple, Simple.Endpoint,
# https: [
# port: 443,
# cipher_suite: :strong,
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH"),
# transport_options: [socket_opts: [:inet6]]
# ]
#
# The `cipher_suite` is set to `:strong` to support only the
# latest and more secure SSL ciphers. This means old browsers
# and clients may not be supported. You can set it to
# `:compatible` for wider support.
#
# `:keyfile` and `:certfile` expect an absolute path to the key
# and cert in disk or a relative path inside priv, for example
# "priv/ssl/server.key". For all supported SSL configuration
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
#
# We also recommend setting `force_ssl` in your endpoint, ensuring
# no data is ever sent via http, always redirecting to https:
#
# config :simple, SimpleWeb.Endpoint,
# force_ssl: [hsts: true]
#
# Check `Plug.SSL` for all available options in `force_ssl`.

# ## Using releases
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start the server for all endpoints:
#
# config :phoenix, :serve_endpoints, true
#
# Alternatively, you can configure exactly which server to
# start per endpoint:
#
# config :simple, Simple.Endpoint, server: true
#
# You will also need to set the application root to `.` in order
# for the new static assets to be served after a hot upgrade:
#
# config :simple, Simple.Endpoint, root: "."

# Finally import the config/prod.secret.exs
# which should be versioned separately.
# import_config "prod.secret.exs"
# Finally import the config/prod.secret.exs which loads secrets
# and configuration from environment variables.
import_config "prod.secret.exs"
41 changes: 41 additions & 0 deletions examples/simple/config/prod.secret.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# In this file, we load production configuration and secrets
# from environment variables. You can also hardcode secrets,
# although such is generally not recommended and you have to
# remember to add this file to your .gitignore.
use Mix.Config

database_url =
System.get_env("DATABASE_URL") ||
raise """
environment variable DATABASE_URL is missing.
For example: ecto://USER:PASS@HOST/DATABASE
"""

config :simple, Simple.Repo,
# ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")

secret_key_base =
System.get_env("SECRET_KEY_BASE") ||
raise """
environment variable SECRET_KEY_BASE is missing.
You can generate one by calling: mix phx.gen.secret
"""

config :simple, SimpleWeb.Endpoint,
http: [
port: String.to_integer(System.get_env("PORT") || "4000"),
transport_options: [socket_opts: [:inet6]]
],
secret_key_base: secret_key_base

# ## Using releases (Elixir v1.9+)
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start each relevant endpoint:
#
# config :simple, SimpleWeb.Endpoint, server: true
#
# Then you can assemble a release by calling `mix release`.
# See `mix help release` for more information.
23 changes: 13 additions & 10 deletions examples/simple/config/test.exs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
use Mix.Config

# Configure your database
#
# The MIX_TEST_PARTITION environment variable can be used
# to provide built-in test partitioning in CI environment.
# Run `mix help test` for more information.
config :simple, Simple.Repo,
username: "postgres",
password: "postgres",
database: "simple_test#{System.get_env("MIX_TEST_PARTITION")}",
hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox

# We don't run a server during test. If one is required,
# you can enable the server option below.
config :simple, SimpleWeb.Endpoint,
http: [port: 4001],
http: [port: 4002],
server: false

# Print only warnings and errors during test
config :logger, level: :warn

# Configure your database
config :simple, Simple.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "simple_test",
hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox
24 changes: 14 additions & 10 deletions examples/simple/lib/simple/application.ex
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
defmodule Simple.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false

use Application
import Supervisor.Spec, only: [supervisor: 2]

# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
PhoenixSwagger.Validator.parse_swagger_schema("priv/static/swagger.json")

# Define workers and child supervisors to be supervised
children = [
# Start the Ecto repository
supervisor(Simple.Repo, []),
# Start the endpoint when the application starts
supervisor(SimpleWeb.Endpoint, [])
# Start your own worker by calling: Simple.Worker.start_link(arg1, arg2, arg3)
# worker(Simple.Worker, [arg1, arg2, arg3]),
Simple.Repo,
# Start the Telemetry supervisor
SimpleWeb.Telemetry,
# Start the PubSub system
{Phoenix.PubSub, name: Simple.PubSub},
# Start the Endpoint (http/https)
SimpleWeb.Endpoint
# Start a worker by calling: Simple.Worker.start_link(arg)
# {Simple.Worker, arg}
]

# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Simple.Supervisor]
Supervisor.start_link(children, opts)
Expand Down
Loading