Skip to content

Commit

Permalink
mix phx.new app -- create new Phoenix 1.7 app for #29
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Nov 4, 2023
1 parent 5552d84 commit d300784
Show file tree
Hide file tree
Showing 43 changed files with 1,301 additions and 546 deletions.
4 changes: 2 additions & 2 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
import_deps: [:phoenix],
inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"]
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}"]
]
17 changes: 12 additions & 5 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
# and its dependencies with the aid of the Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.

# General application configuration
import Config

config :app,
generators: [timestamp_type: :utc_datetime]

# Configures the endpoint
config :app, AppWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "uisVurG8vaSjOECCS6RQVvzPzyBpZ7XZ9Sn2cT2TrajQX+J+KqFsfWK/eyyaqki+",
render_errors: [view: AppWeb.ErrorView, accepts: ~w(html json)],
pubsub_server: App.PubSub
adapter: Phoenix.Endpoint.Cowboy2Adapter,
render_errors: [
formats: [html: AppWeb.ErrorHTML, json: AppWeb.ErrorJSON],
layout: false
],
pubsub_server: App.PubSub,
live_view: [signing_salt: "xcoMLupd"]

# Configures Elixir's Logger
config :logger, :console,
Expand All @@ -24,4 +31,4 @@ 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"
import_config "#{config_env()}.exs"
49 changes: 40 additions & 9 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,53 @@ import Config
# 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.
# watchers to your application. For example, we can use it
# to bundle .js and .css sources.
config :app, AppWeb.Endpoint,
http: [port: 4000],
debug_errors: true,
# Binding to loopback ipv4 address prevents access from other machines.
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
http: [ip: {127, 0, 0, 1}, port: 4000],
check_origin: false,
code_reloader: true,
check_origin: false
debug_errors: true,
secret_key_base: "KI3E1INmNOHt1AIs1yWNeIIM4enQ+agHE9tXvqTuNHJEkUgWoRkyzNFdYRy/9Ge7",
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
#
# 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_web/views/.*(ex)$},
~r{lib/app_web/templates/.*(eex)$}
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"lib/app_web/(controllers|live|components)/.*(ex|heex)$"
]
]

# Enable dev routes for dashboard and mailbox
config :app, dev_routes: true

# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"

Expand All @@ -32,3 +60,6 @@ config :phoenix, :stacktrace_depth, 20

# Initialize plugs at runtime for faster development compilation
config :phoenix, :plug_init_mode, :runtime

# Include HEEx debug annotations as HTML comments in rendered markup
config :phoenix_live_view, :debug_heex_annotations, true
17 changes: 3 additions & 14 deletions config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import 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 :app, AppWeb.Endpoint,
http: [:inet6, port: System.get_env("PORT") || 4000],
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

# Runtime production configuration, including reading
# of environment variables, is done on config/runtime.exs.
34 changes: 34 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ if config_env() == :prod do
host = System.get_env("PHX_HOST") || "example.com"
port = String.to_integer(System.get_env("PORT") || "4000")

config :app, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")

config :app, AppWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"],
http: [
Expand All @@ -47,4 +49,36 @@ if config_env() == :prod do
port: port
],
secret_key_base: secret_key_base

# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
# to your endpoint configuration:
#
# config :app, AppWeb.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")
# ]
#
# 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, AppWeb.Endpoint,
# force_ssl: [hsts: true]
#
# Check `Plug.SSL` for all available options in `force_ssl`.
end
19 changes: 5 additions & 14 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@ import Config
# We don't run a server during test. If one is required,
# you can enable the server option below.
config :app, AppWeb.Endpoint,
http: [port: 4002],
http: [ip: {127, 0, 0, 1}, port: 4002],
secret_key_base: "Hgwn7B7v8EcxKAGpJ65aTAmpz2dKRTUGG3q1wquHD88VG4Tfm0IyH8bJvUsqNLSC",
server: false

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

# Configure your database
config :app, App.Repo,
username: "postgres",
password: "postgres",
database: "app_test",
hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox

config :elixir_auth_github,
client_id: "d6fca75c63daa014c187",
client_secret: "8eeb143935d1a505692aaef856db9b4da8245f3c",
httpoison_mock: true
# Initialize plugs at runtime for faster test compilation
config :phoenix, :plug_init_mode, :runtime
13 changes: 8 additions & 5 deletions lib/app/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ defmodule App.Application do

use Application

@impl true
def start(_type, _args) do
# List all child processes to be supervised
children = [
# Start the endpoint when the application starts
AppWeb.Endpoint,
{Phoenix.PubSub, [name: App.PubSub, adapter: Phoenix.PubSub.PG2]}
# Starts a worker by calling: App.Worker.start_link(arg)
AppWeb.Telemetry,
{DNSCluster, query: Application.get_env(:app, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: App.PubSub},
# Start a worker by calling: App.Worker.start_link(arg)
# {App.Worker, arg},
# Start to serve requests, typically the last entry
AppWeb.Endpoint
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand All @@ -23,6 +25,7 @@ defmodule App.Application do

# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
@impl true
def config_change(changed, _new, removed) do
AppWeb.Endpoint.config_change(changed, removed)
:ok
Expand Down
19 changes: 0 additions & 19 deletions lib/app/release.ex

This file was deleted.

93 changes: 69 additions & 24 deletions lib/app_web.ex
Original file line number Diff line number Diff line change
@@ -1,59 +1,104 @@
defmodule AppWeb do
@moduledoc """
The entrypoint for defining your web interface, such
as controllers, views, channels and so on.
as controllers, components, channels, and so on.
This can be used in your application as:
use AppWeb, :controller
use AppWeb, :view
use AppWeb, :html
The definitions below will be executed for every view,
controller, etc, so keep them short and clean, focused
The definitions below will be executed for every controller,
component, etc, so keep them short and clean, focused
on imports, uses and aliases.
Do NOT define functions inside the quoted expressions
below. Instead, define any helper function in modules
and import those modules here.
below. Instead, define additional modules and import
those modules here.
"""

def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)

def router do
quote do
use Phoenix.Router, helpers: false

# Import common connection and controller functions to use in pipelines
import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveView.Router
end
end

def channel do
quote do
use Phoenix.Channel
end
end

def controller do
quote do
use Phoenix.Controller, namespace: AppWeb
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: AppWeb.Layouts]

import Plug.Conn
alias AppWeb.Router.Helpers, as: Routes

unquote(verified_routes())
end
end

def view do
def live_view do
quote do
use Phoenix.View,
root: "lib/app_web/templates",
namespace: AppWeb
use Phoenix.LiveView,
layout: {AppWeb.Layouts, :app}

# Import convenience functions from controllers
import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1]
unquote(html_helpers())
end
end

# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
def live_component do
quote do
use Phoenix.LiveComponent

import AppWeb.ErrorHelpers
alias AppWeb.Router.Helpers, as: Routes
unquote(html_helpers())
end
end

def router do
def html do
quote do
use Phoenix.Router
import Plug.Conn
import Phoenix.Controller
use Phoenix.Component

# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_csrf_token: 0, view_module: 1, view_template: 1]

# Include general helpers for rendering HTML
unquote(html_helpers())
end
end

def channel do
defp html_helpers do
quote do
use Phoenix.Channel
# HTML escaping functionality
import Phoenix.HTML
# Core UI components and translation
import AppWeb.CoreComponents

# Shortcut for generating JS commands
alias Phoenix.LiveView.JS

# Routes generation with the ~p sigil
unquote(verified_routes())
end
end

def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
endpoint: AppWeb.Endpoint,
router: AppWeb.Router,
statics: AppWeb.static_paths()
end
end

Expand Down
Loading

0 comments on commit d300784

Please sign in to comment.