From d89b83c9325ae3f13f01fb42e91ce9b2836be9cd Mon Sep 17 00:00:00 2001 From: Robert Prehn Date: Wed, 30 Sep 2020 15:56:22 -0500 Subject: [PATCH 1/2] chore: Make configs consistent --- apps/content/config/config.exs | 26 ---- apps/content/config/dev.exs | 76 ---------- apps/content/config/test.exs | 4 - .../test/content/markup_field_test.exs | 2 +- apps/core/config/config.exs | 31 ---- apps/core/config/dev.exs | 76 ---------- apps/core/config/prod.exs | 55 -------- apps/core/config/prod.secret.exs | 41 ------ apps/core/config/test.exs | 22 --- config/config.exs | 101 ++++++------- config/dev.exs | 115 ++++++++++----- config/prod.exs | 133 +----------------- config/test.exs | 12 ++ 13 files changed, 147 insertions(+), 547 deletions(-) delete mode 100644 apps/content/config/config.exs delete mode 100644 apps/content/config/dev.exs delete mode 100644 apps/content/config/test.exs delete mode 100644 apps/core/config/config.exs delete mode 100644 apps/core/config/dev.exs delete mode 100644 apps/core/config/prod.exs delete mode 100644 apps/core/config/prod.secret.exs delete mode 100644 apps/core/config/test.exs diff --git a/apps/content/config/config.exs b/apps/content/config/config.exs deleted file mode 100644 index 48625319..00000000 --- a/apps/content/config/config.exs +++ /dev/null @@ -1,26 +0,0 @@ -# This file is responsible for configuring your application -# and its dependencies with the aid of the Mix.Config module. -# -# This configuration file is loaded before any dependency and -# is restricted to this project. -use Mix.Config - -# General application configuration -config :content, - ecto_repos: [Content.Repo] - -config :phoenix, :json_library, Jason - -# Configures Elixir's Logger -config :logger, :console, - format: "$time $metadata[$level] $message\n", - metadata: [:user_id] - -config :content, Content.Scheduler, - jobs: [ - {"@hourly", {Content.Sitemaps, :generate, []}} - ] - -# 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" diff --git a/apps/content/config/dev.exs b/apps/content/config/dev.exs deleted file mode 100644 index 604d7be0..00000000 --- a/apps/content/config/dev.exs +++ /dev/null @@ -1,76 +0,0 @@ -use Mix.Config - -# Configure your database -config :content, Content.Repo, - username: "postgres", - password: "postgres", - database: "legendary_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 webpack to recompile .js and .css sources. -config :content, Content.Endpoint, - http: [port: 4000], - debug_errors: true, - code_reloader: true, - check_origin: false, - watchers: [ - node: [ - "node_modules/webpack/bin/webpack.js", - "--mode", - "development", - "--watch-stdin", - cd: Path.expand("../assets", __DIR__) - ] - ] - -# ## 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. - -# Watch static and templates for browser reloading. -config :content, Content.Endpoint, - live_reload: [ - patterns: [ - ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", - ~r"priv/gettext/.*(po)$", - ~r"lib/content_web/(live|views)/.*(ex)$", - ~r"lib/content_web/templates/.*(eex)$" - ] - ] - -# Do not include metadata nor timestamps in development logs -config :logger, :console, format: "[$level] $message\n" - -# Set a higher stacktrace during development. Avoid configuring such -# in production as building large stacktraces may be expensive. -config :phoenix, :stacktrace_depth, 20 - -# Initialize plugs at runtime for faster development compilation -config :phoenix, :plug_init_mode, :runtime diff --git a/apps/content/config/test.exs b/apps/content/config/test.exs deleted file mode 100644 index af29307c..00000000 --- a/apps/content/config/test.exs +++ /dev/null @@ -1,4 +0,0 @@ -use Mix.Config - -# Print only warnings and errors during test -config :logger, level: :warn diff --git a/apps/content/test/content/markup_field_test.exs b/apps/content/test/content/markup_field_test.exs index c54e6260..3be60557 100644 --- a/apps/content/test/content/markup_field_test.exs +++ b/apps/content/test/content/markup_field_test.exs @@ -38,7 +38,7 @@ defmodule Content.MarkupFieldTest do end test "render_form/5 makes a field with a simplemde data attribute" do - safe = render_form(nil, nil, form, :boop, %{}) + safe = render_form(nil, nil, form(), :boop, %{}) assert safe_to_string(safe) =~ "data-simplemde" end diff --git a/apps/core/config/config.exs b/apps/core/config/config.exs deleted file mode 100644 index 13dea213..00000000 --- a/apps/core/config/config.exs +++ /dev/null @@ -1,31 +0,0 @@ -# This file is responsible for configuring your application -# and its dependencies with the aid of the Mix.Config module. -# -# This configuration file is loaded before any dependency and -# is restricted to this project. - -# General application configuration -use Mix.Config - -config :core, - ecto_repos: [Core.Repo] - -# Configures the endpoint -config :core, AppWeb.Endpoint, - url: [host: "localhost"], - secret_key_base: "kNJbLKCmuZYSK99S55+DmirA2TlmOxzs/xz3xnlXtOhQCoBMmYRabaRLTXkcsw5d", - render_errors: [view: CoreWeb.ErrorView, accepts: ~w(html json), layout: false], - pubsub_server: Core.PubSub, - live_view: [signing_salt: "Nb8V5NUr"] - -# 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 - -# 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" diff --git a/apps/core/config/dev.exs b/apps/core/config/dev.exs deleted file mode 100644 index 8803d265..00000000 --- a/apps/core/config/dev.exs +++ /dev/null @@ -1,76 +0,0 @@ -use Mix.Config - -# Configure your database -config :core, Core.Repo, - username: "postgres", - password: "postgres", - database: "legendary_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 webpack to recompile .js and .css sources. -# config :core, CoreWeb.Endpoint, -# http: [port: 4000], -# debug_errors: true, -# code_reloader: true, -# check_origin: false, -# watchers: [ -# node: [ -# "node_modules/webpack/bin/webpack.js", -# "--mode", -# "development", -# "--watch-stdin", -# cd: Path.expand("../assets", __DIR__) -# ] -# ] - -# ## 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. - -# Watch static and templates for browser reloading. -config :core, CoreWeb.Endpoint, - live_reload: [ - patterns: [ - ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", - ~r"priv/gettext/.*(po)$", - ~r"lib/core_web/(live|views)/.*(ex)$", - ~r"lib/core_web/templates/.*(eex)$" - ] - ] - -# Do not include metadata nor timestamps in development logs -config :logger, :console, format: "[$level] $message\n" - -# Set a higher stacktrace during development. Avoid configuring such -# in production as building large stacktraces may be expensive. -config :phoenix, :stacktrace_depth, 20 - -# Initialize plugs at runtime for faster development compilation -config :phoenix, :plug_init_mode, :runtime diff --git a/apps/core/config/prod.exs b/apps/core/config/prod.exs deleted file mode 100644 index 8384bee4..00000000 --- a/apps/core/config/prod.exs +++ /dev/null @@ -1,55 +0,0 @@ -use Mix.Config - -# For production, don't forget to configure the url host -# to something meaningful, Phoenix uses this information -# when generating URLs. -# -# Note we also include the path to a cache manifest -# containing the digested version of static files. This -# 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 :core, AppWeb.Endpoint, - 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 - -# ## 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 :core, CoreWeb.Endpoint, -# ... -# url: [host: "example.com", port: 443], -# 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 :core, CoreWeb.Endpoint, -# force_ssl: [hsts: true] -# -# Check `Plug.SSL` for all available options in `force_ssl`. - -# Finally import the config/prod.secret.exs which loads secrets -# and configuration from environment variables. -import_config "prod.secret.exs" diff --git a/apps/core/config/prod.secret.exs b/apps/core/config/prod.secret.exs deleted file mode 100644 index 45dd55cc..00000000 --- a/apps/core/config/prod.secret.exs +++ /dev/null @@ -1,41 +0,0 @@ -# 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 :core, Core.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 :core, AppWeb.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 :core, CoreWeb.Endpoint, server: true -# -# Then you can assemble a release by calling `mix release`. -# See `mix help release` for more information. diff --git a/apps/core/config/test.exs b/apps/core/config/test.exs deleted file mode 100644 index a995d69a..00000000 --- a/apps/core/config/test.exs +++ /dev/null @@ -1,22 +0,0 @@ -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 :core, Core.Repo, - username: "postgres", - password: "postgres", - database: "legendary_test#{System.get_env("MIX_TEST_PARTITION")}", - hostname: System.get_env("DATABASE_URL") || "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 :core, AppWeb.Endpoint, - http: [port: 4002], - server: false - -# Print only warnings and errors during test -config :logger, level: :warn diff --git a/config/config.exs b/config/config.exs index 5c298b1e..e8218db8 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,29 +1,5 @@ use Mix.Config -# Configures the endpoint -config :app, App.Endpoint, - url: [host: "localhost"], - secret_key_base: "TOB3UL0s6bHCiBoCnflb5GZTHlA6gvvq2BlRurVQca0WcK8Lf+b2xq/KahpWSvJs", - render_errors: [view: App.ErrorView, accepts: ~w(html json), layout: false], - pubsub_server: App.PubSub, - live_view: [signing_salt: "H9ynuZL0"] - -config :admin, - ecto_repos: [Admin.Repo], - generators: [context_app: false] - -config :app, - ecto_repos: [App.Repo], - generators: [context_app: :app] - -# Configures the endpoint -config :admin, Admin.Endpoint, - url: [host: "localhost"], - secret_key_base: "r2eN53mJ9RmlGz9ZQ7xf43P3Or59aaO9rdf5D3hRcsuiH44pGW9kPGfl5mt9N1Gi", - render_errors: [view: Admin.ErrorView, accepts: ~w(html json), layout: false], - pubsub_server: Admin.PubSub, - live_view: [signing_salt: "g5ltUbnQ"] - # Configures the endpoint config :app, AppWeb.Endpoint, url: [host: "localhost"], @@ -32,24 +8,13 @@ config :app, AppWeb.Endpoint, pubsub_server: App.PubSub, live_view: [signing_salt: "g5ltUbnQ"] -# Configure Mix tasks and generators -config :auth, - ecto_repos: [Auth.Repo] +config :admin, Admin.Endpoint, + url: [host: "localhost"], + secret_key_base: "r2eN53mJ9RmlGz9ZQ7xf43P3Or59aaO9rdf5D3hRcsuiH44pGW9kPGfl5mt9N1Gi", + render_errors: [view: Admin.ErrorView, accepts: ~w(html json), layout: false], + pubsub_server: Admin.PubSub, + live_view: [signing_salt: "g5ltUbnQ"] -config :auth_web, - ecto_repos: [Auth.Repo], - generators: [context_app: :auth] - -config :auth_web, :pow, - user: Auth.User, - repo: Auth.Repo, - extensions: [PowEmailConfirmation, PowPersistentSession, PowResetPassword], - controller_callbacks: Pow.Extension.Phoenix.ControllerCallbacks, - mailer_backend: AuthWeb.Pow.Mailer, - web_mailer_module: AuthWeb, - web_module: AuthWeb - -# Configures the endpoint config :auth_web, AuthWeb.Endpoint, url: [host: "localhost"], secret_key_base: "cjtU4RvTirW4yJZDkdqZJmaj7bvaQRrX6mevkoGYqzEuMujV/Q0w3utlO5+FUsUj", @@ -64,19 +29,54 @@ config :content, Content.Endpoint, pubsub_server: Content.PubSub, live_view: [signing_salt: "Nb8V5NUr"] -config :admin, - ecto_repos: [Admin.Repo] - -config :core, email_from: "example@example.org" - -config :content, - generators: [context_app: false] +config :core, CoreWeb.Endpoint, + url: [host: "localhost"], + secret_key_base: "kNJbLKCmuZYSK99S55+DmirA2TlmOxzs/xz3xnlXtOhQCoBMmYRabaRLTXkcsw5d", + render_errors: [view: CoreWeb.ErrorView, accepts: ~w(html json), layout: false], + pubsub_server: Core.PubSub, + live_view: [signing_salt: "Nb8V5NUr"] config :content, Content.Endpoint, server: false config :auth_web, AuthWeb.Endpoint, server: false config :admin, Admin.Endpoint, server: false config :app, CoreWeb.Endpoint, server: false +# Configure Mix tasks and generators +config :admin, + ecto_repos: [Admin.Repo], + generators: [context_app: false] + +config :app, + ecto_repos: [App.Repo], + generators: [context_app: :app] + +config :auth, + ecto_repos: [Auth.Repo] + +config :auth_web, + ecto_repos: [Auth.Repo], + generators: [context_app: :auth] + +config :content, + ecto_repos: [Content.Repo] + +config :core, + ecto_repos: [Core.Repo] + +config :auth_web, :pow, + user: Auth.User, + repo: Auth.Repo, + extensions: [PowEmailConfirmation, PowPersistentSession, PowResetPassword], + controller_callbacks: Pow.Extension.Phoenix.ControllerCallbacks, + mailer_backend: AuthWeb.Pow.Mailer, + web_mailer_module: AuthWeb, + web_module: AuthWeb + +config :core, email_from: "example@example.org" + +config :content, + generators: [context_app: false] + import_config "../apps/*/config/config.exs" # Configures Elixir's Logger @@ -89,6 +89,11 @@ config :phoenix, :json_library, Jason config :linguist, pluralization_key: :count +config :content, Content.Scheduler, + jobs: [ + {"@hourly", {Content.Sitemaps, :generate, []}} + ] + import_config "email_styles.exs" import_config "admin.exs" diff --git a/config/dev.exs b/config/dev.exs index 6d78e962..26855e0b 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -21,6 +21,51 @@ config :app, AppWeb.Endpoint, ] ] +config :admin, Admin.Endpoint, + http: [port: 4000], + debug_errors: true, + code_reloader: true, + check_origin: false, + watchers: [ + node: [ + "node_modules/webpack/bin/webpack.js", + "--mode", + "development", + "--watch-stdin", + cd: Path.expand("../apps/admin/assets", __DIR__) + ] + ] + +config :auth_web, AuthWeb.Endpoint, + http: [port: 4000], + debug_errors: true, + code_reloader: true, + check_origin: false, + watchers: [ + node: [ + "node_modules/webpack/bin/webpack.js", + "--mode", + "development", + "--watch-stdin", + cd: Path.expand("../apps/auth_web/assets", __DIR__) + ] + ] + +config :content, Content.Endpoint, + http: [port: 4000], + debug_errors: true, + code_reloader: true, + check_origin: false, + watchers: [ + node: [ + "node_modules/webpack/bin/webpack.js", + "--mode", + "development", + "--watch-stdin", + cd: Path.expand("../assets", __DIR__) + ] + ] + # ## SSL Support # # In order to use HTTPS in development, a self-signed @@ -56,24 +101,13 @@ config :app, AppWeb.Endpoint, ] ] -# 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 webpack to recompile .js and .css sources. -config :admin, Admin.Endpoint, - http: [port: 4000], - debug_errors: true, - code_reloader: true, - check_origin: false, - watchers: [ - node: [ - "node_modules/webpack/bin/webpack.js", - "--mode", - "development", - "--watch-stdin", - cd: Path.expand("../apps/admin/assets", __DIR__) +config :content, Content.Endpoint, + live_reload: [ + patterns: [ + ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", + ~r"priv/gettext/.*(po)$", + ~r"lib/content_web/(live|views)/.*(ex)$", + ~r"lib/content_web/templates/.*(eex)$" ] ] @@ -139,26 +173,21 @@ config :app, App.Repo, 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 webpack to recompile .js and .css sources. -config :auth_web, AuthWeb.Endpoint, - http: [port: 4000], - debug_errors: true, - code_reloader: true, - check_origin: false, - watchers: [ - node: [ - "node_modules/webpack/bin/webpack.js", - "--mode", - "development", - "--watch-stdin", - cd: Path.expand("../apps/auth_web/assets", __DIR__) - ] - ] +config :content, Content.Repo, + username: "postgres", + password: "postgres", + database: "legendary_dev", + hostname: "localhost", + show_sensitive_data_on_connection_error: true, + pool_size: 10 + +config :core, Core.Repo, + username: "postgres", + password: "postgres", + database: "legendary_dev", + hostname: "localhost", + show_sensitive_data_on_connection_error: true, + pool_size: 10 # ## SSL Support # @@ -195,6 +224,16 @@ config :auth_web, AuthWeb.Endpoint, ] ] +config :core, CoreWeb.Endpoint, + live_reload: [ + patterns: [ + ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", + ~r"priv/gettext/.*(po)$", + ~r"lib/core_web/(live|views)/.*(ex)$", + ~r"lib/core_web/templates/.*(eex)$" + ] + ] + # For development, we disable any cache and enable # debugging and code reloading. # diff --git a/config/prod.exs b/config/prod.exs index 4bc6135e..ae78fe47 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -13,147 +13,22 @@ config :app, App.Endpoint, url: [host: "example.com", port: 80], cache_static_manifest: "priv/static/cache_manifest.json" -# ## 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 :app, App.Endpoint, -# ... -# url: [host: "example.com", port: 443], -# 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 :app, App.Endpoint, -# force_ssl: [hsts: true] -# -# Check `Plug.SSL` for all available options in `force_ssl`. - -# For production, don't forget to configure the url host -# to something meaningful, Phoenix uses this information -# when generating URLs. -# -# Note we also include the path to a cache manifest -# containing the digested version of static files. This -# 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 :admin, Admin.Endpoint, url: [host: "example.com", port: 80], cache_static_manifest: "priv/static/cache_manifest.json" -# ## 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 :admin, Admin.Endpoint, -# ... -# url: [host: "example.com", port: 443], -# 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 :admin, Admin.Endpoint, -# force_ssl: [hsts: true] -# -# Check `Plug.SSL` for all available options in `force_ssl`. - -# For production, don't forget to configure the url host -# to something meaningful, Phoenix uses this information -# when generating URLs. -# -# Note we also include the path to a cache manifest -# containing the digested version of static files. This -# 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 :auth_web, AuthWeb.Endpoint, url: [host: "example.com", port: 80], cache_static_manifest: "priv/static/cache_manifest.json" -# ## 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 :auth_web, AuthWeb.Endpoint, -# ... -# url: [host: "example.com", port: 443], -# 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 :auth_web, AuthWeb.Endpoint, -# force_ssl: [hsts: true] -# -# Check `Plug.SSL` for all available options in `force_ssl`. - -# For production, don't forget to configure the url host -# to something meaningful, Phoenix uses this information -# when generating URLs. -# -# Note we also include the path to a cache manifest -# containing the digested version of static files. This -# 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 :content, Content.Endpoint, url: [host: "example.com", port: 80], cache_static_manifest: "priv/static/cache_manifest.json" +config :core, AppWeb.Endpoint, + url: [host: "example.com", port: 80], + cache_static_manifest: "priv/static/cache_manifest.json" + # ## SSL Support # # To get SSL working, you will need to add the `https` key diff --git a/config/test.exs b/config/test.exs index 7d4ed3ec..bce5c1ef 100644 --- a/config/test.exs +++ b/config/test.exs @@ -31,6 +31,13 @@ config :content, Content.Repo, hostname: System.get_env("DATABASE_URL") || "localhost", pool: Ecto.Adapters.SQL.Sandbox +config :core, Core.Repo, + username: "postgres", + password: "postgres", + database: "legendary_test#{System.get_env("MIX_TEST_PARTITION")}", + hostname: System.get_env("DATABASE_URL") || "localhost", + pool: Ecto.Adapters.SQL.Sandbox + config :admin, Admin.Repo, username: "postgres", password: "postgres", @@ -57,5 +64,10 @@ config :content, Content.Endpoint, http: [port: 4002], server: false +config :core, AppWeb.Endpoint, + http: [port: 4002], + server: false config :core, CoreMailer, adapter: Bamboo.TestAdapter + +config :logger, level: :warn From f6aae2f0cbb81a3fa55a6d2e9adcd4d56cff9212 Mon Sep 17 00:00:00 2001 From: Robert Prehn Date: Wed, 30 Sep 2020 16:31:03 -0500 Subject: [PATCH 2/2] feat: DRY up configs --- config/config.exs | 96 +++++-------- config/dev.exs | 349 ++++++++++------------------------------------ config/test.exs | 85 ++++------- 3 files changed, 131 insertions(+), 399 deletions(-) diff --git a/config/config.exs b/config/config.exs index e8218db8..aa4297ea 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,67 +1,44 @@ use Mix.Config -# Configures the endpoint -config :app, AppWeb.Endpoint, +[ + {:admin, Admin, false}, + {:app, AppWeb, true}, + {:auth_web, AuthWeb, false}, + {:content, Content, false}, + {:core, CoreWeb, false}, +] +|> Enum.map(fn {otp_app, module, start_server} -> + endpoint = Module.concat(module, "Endpoint") + error_view = Module.concat(module, "ErrorView") + + config otp_app, endpoint, url: [host: "localhost"], secret_key_base: "r2eN53mJ9RmlGz9ZQ7xf43P3Or59aaO9rdf5D3hRcsuiH44pGW9kPGfl5mt9N1Gi", - render_errors: [view: AppWeb.ErrorView, accepts: ~w(html json), layout: false], + render_errors: [view: error_view, accepts: ~w(html json), layout: false], pubsub_server: App.PubSub, - live_view: [signing_salt: "g5ltUbnQ"] + live_view: [signing_salt: "g5ltUbnQ"], + server: start_server +end) -config :admin, Admin.Endpoint, - url: [host: "localhost"], - secret_key_base: "r2eN53mJ9RmlGz9ZQ7xf43P3Or59aaO9rdf5D3hRcsuiH44pGW9kPGfl5mt9N1Gi", - render_errors: [view: Admin.ErrorView, accepts: ~w(html json), layout: false], - pubsub_server: Admin.PubSub, - live_view: [signing_salt: "g5ltUbnQ"] +[ + {:admin, Admin.Repo}, + {:app, App.Repo}, + {:auth, Auth.Repo}, + {:auth_web, Auth.Repo, :auth}, + {:content, Content.Repo}, + {:core, Core.Repo}, +] +|> Enum.map(fn + {otp_app, repo} -> + config otp_app, + ecto_repos: [repo], + generators: [context_app: otp_app] -config :auth_web, AuthWeb.Endpoint, - url: [host: "localhost"], - secret_key_base: "cjtU4RvTirW4yJZDkdqZJmaj7bvaQRrX6mevkoGYqzEuMujV/Q0w3utlO5+FUsUj", - render_errors: [view: AuthWeb.ErrorView, accepts: ~w(html json), layout: false], - pubsub_server: AuthWeb.PubSub, - live_view: [signing_salt: "AwljJYaY"] - -config :content, Content.Endpoint, - url: [host: "localhost"], - secret_key_base: "kNJbLKCmuZYSK99S55+DmirA2TlmOxzs/xz3xnlXtOhQCoBMmYRabaRLTXkcsw5d", - render_errors: [view: Content.ErrorView, accepts: ~w(html json), layout: false], - pubsub_server: Content.PubSub, - live_view: [signing_salt: "Nb8V5NUr"] - -config :core, CoreWeb.Endpoint, - url: [host: "localhost"], - secret_key_base: "kNJbLKCmuZYSK99S55+DmirA2TlmOxzs/xz3xnlXtOhQCoBMmYRabaRLTXkcsw5d", - render_errors: [view: CoreWeb.ErrorView, accepts: ~w(html json), layout: false], - pubsub_server: Core.PubSub, - live_view: [signing_salt: "Nb8V5NUr"] - -config :content, Content.Endpoint, server: false -config :auth_web, AuthWeb.Endpoint, server: false -config :admin, Admin.Endpoint, server: false -config :app, CoreWeb.Endpoint, server: false - -# Configure Mix tasks and generators -config :admin, - ecto_repos: [Admin.Repo], - generators: [context_app: false] - -config :app, - ecto_repos: [App.Repo], - generators: [context_app: :app] - -config :auth, - ecto_repos: [Auth.Repo] - -config :auth_web, - ecto_repos: [Auth.Repo], - generators: [context_app: :auth] - -config :content, - ecto_repos: [Content.Repo] - -config :core, - ecto_repos: [Core.Repo] + {otp_app, repo, context_app} -> + config otp_app, + ecto_repos: [repo], + generators: [context_app: context_app] +end) config :auth_web, :pow, user: Auth.User, @@ -74,11 +51,6 @@ config :auth_web, :pow, config :core, email_from: "example@example.org" -config :content, - generators: [context_app: false] - -import_config "../apps/*/config/config.exs" - # Configures Elixir's Logger config :logger, :console, format: "$time $metadata[$level] $message\n", diff --git a/config/dev.exs b/config/dev.exs index 26855e0b..77548d61 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -6,288 +6,79 @@ use Mix.Config # The watchers configuration can be used to run external # watchers to your application. For example, we use it # with webpack to recompile .js and .css sources. -config :app, AppWeb.Endpoint, - http: [port: 4000], - debug_errors: true, - code_reloader: true, - check_origin: false, - watchers: [ - node: [ - "node_modules/webpack/bin/webpack.js", - "--mode", - "development", - "--watch-stdin", - cd: Path.expand("../apps/app/assets", __DIR__) +[ + {:admin, Admin}, + {:app, AppWeb}, + {:auth_web, AuthWeb}, + {:content, Content}, + {:core, CoreWeb}, +] +|> Enum.map(fn {otp_app, module} -> + config otp_app, Module.concat(module, "Endpoint"), + http: [port: 4000], + debug_errors: true, + code_reloader: true, + check_origin: false, + watchers: [ + node: [ + "node_modules/webpack/bin/webpack.js", + "--mode", + "development", + "--watch-stdin", + cd: Path.expand("../apps/#{otp_app}/assets", __DIR__) + ] ] - ] -config :admin, Admin.Endpoint, - http: [port: 4000], - debug_errors: true, - code_reloader: true, - check_origin: false, - watchers: [ - node: [ - "node_modules/webpack/bin/webpack.js", - "--mode", - "development", - "--watch-stdin", - cd: Path.expand("../apps/admin/assets", __DIR__) + config otp_app, Module.concat(module, "Endpoint"), + live_reload: [ + patterns: [ + ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", + ~r"priv/gettext/.*(po)$", + ~r"lib/app/(live|views)/.*(ex)$", + ~r"lib/app/templates/.*(eex)$" + ] ] - ] +end) -config :auth_web, AuthWeb.Endpoint, - http: [port: 4000], - debug_errors: true, - code_reloader: true, - check_origin: false, - watchers: [ - node: [ - "node_modules/webpack/bin/webpack.js", - "--mode", - "development", - "--watch-stdin", - cd: Path.expand("../apps/auth_web/assets", __DIR__) - ] - ] - -config :content, Content.Endpoint, - http: [port: 4000], - debug_errors: true, - code_reloader: true, - check_origin: false, - watchers: [ - node: [ - "node_modules/webpack/bin/webpack.js", - "--mode", - "development", - "--watch-stdin", - cd: Path.expand("../assets", __DIR__) - ] - ] - -# ## 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. - -# Watch static and templates for browser reloading. -config :app, AppWeb.Endpoint, - live_reload: [ - patterns: [ - ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", - ~r"priv/gettext/.*(po)$", - ~r"lib/app/(live|views)/.*(ex)$", - ~r"lib/app/templates/.*(eex)$" - ] - ] - -config :content, Content.Endpoint, - live_reload: [ - patterns: [ - ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", - ~r"priv/gettext/.*(po)$", - ~r"lib/content_web/(live|views)/.*(ex)$", - ~r"lib/content_web/templates/.*(eex)$" - ] - ] - -# ## 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. - -# Watch static and templates for browser reloading. -config :admin, Admin.Endpoint, - live_reload: [ - patterns: [ - ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", - ~r"priv/gettext/.*(po)$", - ~r"lib/admin/(live|views)/.*(ex)$", - ~r"lib/admin/templates/.*(eex)$" - ] - ] - -# Configure your database -config :auth, Auth.Repo, - username: "postgres", - password: "postgres", - database: "legendary_dev", - hostname: "localhost", - show_sensitive_data_on_connection_error: true, - pool_size: 10 - -# Configure your database -config :admin, Admin.Repo, - username: "postgres", - password: "postgres", - database: "legendary_dev", - hostname: "localhost", - show_sensitive_data_on_connection_error: true, - pool_size: 10 - -# Configure your database -config :app, App.Repo, - username: "postgres", - password: "postgres", - database: "legendary_dev", - hostname: "localhost", - show_sensitive_data_on_connection_error: true, - pool_size: 10 - -config :content, Content.Repo, - username: "postgres", - password: "postgres", - database: "legendary_dev", - hostname: "localhost", - show_sensitive_data_on_connection_error: true, - pool_size: 10 - -config :core, Core.Repo, - username: "postgres", - password: "postgres", - database: "legendary_dev", - hostname: "localhost", - show_sensitive_data_on_connection_error: true, - pool_size: 10 - -# ## 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. - -# Watch static and templates for browser reloading. -config :auth_web, AuthWeb.Endpoint, - live_reload: [ - patterns: [ - ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", - ~r"priv/gettext/.*(po)$", - ~r"lib/auth_web/(live|views)/.*(ex)$", - ~r"lib/auth_web/templates/.*(eex)$" - ] - ] - -config :core, CoreWeb.Endpoint, - live_reload: [ - patterns: [ - ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", - ~r"priv/gettext/.*(po)$", - ~r"lib/core_web/(live|views)/.*(ex)$", - ~r"lib/core_web/templates/.*(eex)$" - ] - ] - -# 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 webpack to recompile .js and .css sources. -config :content, Content.Endpoint, - http: [port: 4000], - debug_errors: true, - code_reloader: true, - check_origin: false, - watchers: [ - node: [ - "node_modules/webpack/bin/webpack.js", - "--mode", - "development", - "--watch-stdin", - cd: Path.expand("../apps/content_web/assets", __DIR__) - ] - ] - -# ## 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. - -# Watch static and templates for browser reloading. -config :content, Content.Endpoint, - live_reload: [ - patterns: [ - ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", - ~r"priv/gettext/.*(po)$", - ~r"lib/content_web/(live|views)/.*(ex)$", - ~r"lib/content_web/templates/.*(eex)$" - ] - ] +[ + {:admin, Admin.Repo}, + {:app, App.Repo}, + {:auth, Auth.Repo}, + {:content, Content.Repo}, + {:core, Core.Repo} +] +|> Enum.map(fn {otp_app, repo} -> + config otp_app, repo, + username: "postgres", + password: "postgres", + database: "legendary_dev", + hostname: "localhost", + show_sensitive_data_on_connection_error: true, + pool_size: 10 +end) config :core, CoreMailer, adapter: Bamboo.LocalAdapter + +# ## 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. diff --git a/config/test.exs b/config/test.exs index bce5c1ef..5e4f05ba 100644 --- a/config/test.exs +++ b/config/test.exs @@ -2,71 +2,40 @@ use Mix.Config # We don't run a server during test. If one is required, # you can enable the server option below. -config :app, App.Endpoint, - http: [port: 4002], - server: false - -# We don't run a server during test. If one is required, -# you can enable the server option below. -config :admin, Admin.Endpoint, - http: [port: 4002], - server: false +[ + {:admin, Admin}, + {:app, AppWeb}, + {:auth_web, AuthWeb}, + {:content, Content}, + {:core, CoreWeb}, +] +|> Enum.map(fn {otp_app, module} -> + config otp_app, Module.concat(module, "Endpoint"), + http: [port: 4002], + server: false +end) # 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 :auth, Auth.Repo, - username: "postgres", - password: "postgres", - database: "legendary_test#{System.get_env("MIX_TEST_PARTITION")}", - hostname: System.get_env("DATABASE_URL") || "localhost", - pool: Ecto.Adapters.SQL.Sandbox -config :content, Content.Repo, - username: "postgres", - password: "postgres", - database: "legendary_test#{System.get_env("MIX_TEST_PARTITION")}", - hostname: System.get_env("DATABASE_URL") || "localhost", - pool: Ecto.Adapters.SQL.Sandbox - -config :core, Core.Repo, - username: "postgres", - password: "postgres", - database: "legendary_test#{System.get_env("MIX_TEST_PARTITION")}", - hostname: System.get_env("DATABASE_URL") || "localhost", - pool: Ecto.Adapters.SQL.Sandbox - -config :admin, Admin.Repo, - username: "postgres", - password: "postgres", - database: "legendary_test#{System.get_env("MIX_TEST_PARTITION")}", - hostname: System.get_env("DATABASE_URL") || "localhost", - pool: Ecto.Adapters.SQL.Sandbox - -config :app, App.Repo, - username: "postgres", - password: "postgres", - database: "legendary_test#{System.get_env("MIX_TEST_PARTITION")}", - hostname: System.get_env("DATABASE_URL") || "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 :auth_web, AuthWeb.Endpoint, - http: [port: 4002], - server: false - -# We don't run a server during test. If one is required, -# you can enable the server option below. -config :content, Content.Endpoint, - http: [port: 4002], - server: false - -config :core, AppWeb.Endpoint, - http: [port: 4002], - server: false +[ + {:admin, Admin.Repo}, + {:app, App.Repo}, + {:auth, Auth.Repo}, + {:content, Content.Repo}, + {:core, Core.Repo} +] +|> Enum.map(fn {otp_app, repo} -> + config otp_app, repo, + username: "postgres", + password: "postgres", + database: "legendary_test#{System.get_env("MIX_TEST_PARTITION")}", + hostname: System.get_env("DATABASE_URL") || "localhost", + pool: Ecto.Adapters.SQL.Sandbox +end) config :core, CoreMailer, adapter: Bamboo.TestAdapter