Skip to content
Draft
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: 4 additions & 3 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
import_deps: [:ecto, :phoenix],
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"]
import_deps: [:ecto, :ecto_sql, :phoenix],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
]
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright © 2021 - 2022 Conrad Taylor. All Rights Reserved.
Copyright © 2021 - 2024 Conrad Taylor. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The purpose of this project is to implement an application where fans can commen

- Erlang 26.2.3 or newer

- Phoenix 1.6.16 or newer
- Phoenix 1.17.11 or newer

- PostgreSQL 15.6 or newer

Expand Down
42 changes: 13 additions & 29 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import Config

config :flix,
ecto_repos: [Flix.Repo],
generators: [binary_id: true]
generators: [timestamp_type: :utc_datetime, binary_id: true]

# Configures the endpoint
config :flix, FlixWeb.Endpoint,
adapter: Bandit.PhoenixAdapter,
url: [host: "localhost"],
render_errors: [view: FlixWeb.ErrorView, accepts: ~w(html json), layout: false],
adapter: Bandit.PhoenixAdapter,
render_errors: [
formats: [html: FlixWeb.ErrorHTML, json: FlixWeb.ErrorJSON],
layout: false
],
pubsub_server: Flix.PubSub,
live_view: [signing_salt: "C/wWe4Zy"]
live_view: [signing_salt: "6jqhXaaD"]

# Configures the mailer
#
Expand All @@ -33,33 +36,24 @@ config :swoosh, :api_client, false

# Configure esbuild (the version is required)
config :esbuild,
version: "0.18.11",
default: [
version: "0.17.11",
flix: [
args:
~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
]

# Configure dart_sass (the version is required)
config :dart_sass,
version: "1.61.0",
default: [
args: ~w(css/app.scss ../priv/static/assets/app.css.tailwind),
cd: Path.expand("../assets", __DIR__)
]

# Configure tailwind (the version is required)
config :tailwind,
version: "3.3.2",
default: [
version: "3.4.3",
flix: [
args: ~w(
--config=tailwind.config.js
--input=../priv/static/assets/app.css.tailwind
--input=css/app.css
--output=../priv/static/assets/app.css
),
cd: Path.expand("../assets", __DIR__),
env: %{"BROWSERSLIST_IGNORE_OLD_DATA" => "1"}
cd: Path.expand("../assets", __DIR__)
]

# Configures Elixir's Logger
Expand All @@ -70,16 +64,6 @@ config :logger, :console,
# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason

# Configure the time zone database.
# https://mikezornek.com/posts/2020/3/working-with-time-zones-in-an-elixir-phoenix-app
# https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase

# Configure Bamboo Mailer
config :flix, Flix.Mailer,
adapter: Bamboo.SendGridAdapter,
api_key: System.get_env("SENDGRID_API_KEY")

# Configure mix_test_watch
if Mix.env() == :dev do
config :mix_test_watch,
Expand Down
44 changes: 18 additions & 26 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,29 @@ import Config
config :flix, Flix.Repo,
username: "postgres",
password: "postgres",
database: "flix_dev",
hostname: "localhost",
database: "flix_dev",
stacktrace: true,
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 esbuild to recompile .js and .css sources.
# watchers to your application. For example, we can use it
# to bundle .js and .css sources.
config :flix, FlixWeb.Endpoint,
# 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,
debug_errors: true,
secret_key_base: "tCI4Bo4USd+jHzx1Wj3qeOT4/rhp60jxq/QJqsod9pf4aI/lHaaNAMkgX/9dwM4d",
secret_key_base: "cAV3Rs7tYjMMYLC4iKYTar/gSG0sBrfmUXPHKGOr+I+MRlcHTGxmR8N8pTbMkRM3",
watchers: [
# Start the esbuild watcher by calling Esbuild.install_and_run(:default, args)
esbuild: {
Esbuild,
:install_and_run,
[:default, ~w(--sourcemap=inline --watch)]},
# Start the sass watcher by calling DartSass.install_and_run(:default, args)
sass: {
DartSass,
:install_and_run,
[:default, ~w(--embed-source-map --source-map-urls=absolute --watch)]
},
# Start the tailwind watcher by calling Tailwind.install_and_run(:default, args)
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
esbuild: {Esbuild, :install_and_run, [:flix, ~w(--sourcemap=inline --watch)]},
tailwind: {Tailwind, :install_and_run, [:flix, ~w(--watch)]}
]

# ## SSL Support
Expand All @@ -47,7 +37,6 @@ config :flix, FlixWeb.Endpoint,
#
# 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:
Expand All @@ -67,13 +56,15 @@ config :flix, FlixWeb.Endpoint,
config :flix, FlixWeb.Endpoint,
live_reload: [
patterns: [
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"priv/static/(?!uploads/).*(js|css|png|jpeg|jpg|gif|svg)$",
~r"priv/gettext/.*(po)$",
~r"lib/flix_web/(live|views)/.*(ex)$",
~r"lib/flix_web/templates/.*(eex)$"
~r"lib/flix_web/(controllers|live|components)/.*(ex|heex)$"
]
]

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

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

Expand All @@ -84,12 +75,13 @@ 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

# Disable swoosh api client as it is only required for production adapters.
config :swoosh, :api_client, false

# Set configuration for image upload.
config :waffle,
storage: Waffle.Storage.Local,
asset_host: "http://localhost:4000"

# Set configuation for sending e-mail.
config :flix, Flix.Mailer,
adapter: Bamboo.LocalAdapter,
open_email_in_browser_url: "http://localhost:4000/sent_emails"
21 changes: 11 additions & 10 deletions config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
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,
# manifest is generated by the `mix assets.deploy` task,
# which you should run after static files are built and
# before starting your production server.
config :flix, FlixWeb.Endpoint,
http: [port: {:system, "PORT"}],
url: [scheme: "https", host: "flix-elixir-cwt.herokuapp.com", port: 443],
force_ssl: [rewrite_on: [:x_forwarded_proto]],
cache_static_manifest: "priv/static/cache_manifest.json"
config :flix, FlixWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"

# Configures Swoosh API Client
config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: Flix.Finch

# Disable Swoosh Local Memory Storage
config :swoosh, local: false

# 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.

config :waffle,
storage: Waffle.Storage.S3,
bucket: System.get_env("AWS_BUCKET_NAME"),
Expand Down
64 changes: 54 additions & 10 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ import Config
# and secrets from environment variables or elsewhere. Do not define
# any compile-time configuration in here, as it won't be applied.
# The block below contains prod specific runtime configuration.

# ## Using releases
#
# If you use `mix release`, you need to explicitly enable the server
# by passing the PHX_SERVER=true when you start it:
#
# PHX_SERVER=true bin/flix start
#
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
# script that automatically sets the env var above.
if System.get_env("PHX_SERVER") do
config :flix, FlixWeb.Endpoint, server: true
end

if config_env() == :prod do
database_url =
System.get_env("DATABASE_URL") ||
Expand All @@ -14,11 +28,13 @@ if config_env() == :prod do
For example: ecto://USER:PASS@HOST/DATABASE
"""

maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []

config :flix, Flix.Repo,
# ssl: true,
# socket_options: [:inet6],
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
socket_options: maybe_ipv6

# The secret key base is used to sign/encrypt cookies and other secrets.
# A default value is used in config/dev.exs and config/test.exs but you
Expand All @@ -32,26 +48,54 @@ if config_env() == :prod do
You can generate one by calling: mix phx.gen.secret
"""

host = System.get_env("PHX_HOST") || "example.com"
port = String.to_integer(System.get_env("PORT") || "4000")

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

config :flix, FlixWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"],
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
# See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: String.to_integer(System.get_env("PORT") || "4000")
port: port
],
secret_key_base: secret_key_base

# ## Using releases
# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
# to your endpoint configuration:
#
# config :flix, FlixWeb.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
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start each relevant endpoint:
# We also recommend setting `force_ssl` in your config/prod.exs,
# ensuring no data is ever sent via http, always redirecting to https:
#
# config :flix, FlixWeb.Endpoint, server: true
# config :flix, FlixWeb.Endpoint,
# force_ssl: [hsts: true]
#
# Then you can assemble a release by calling `mix release`.
# See `mix help release` for more information.
# Check `Plug.SSL` for all available options in `force_ssl`.

# ## Configuring the mailer
#
Expand Down
11 changes: 7 additions & 4 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ import Config
config :flix, Flix.Repo,
username: "postgres",
password: "postgres",
database: "flix_test#{System.get_env("MIX_TEST_PARTITION")}",
hostname: "localhost",
database: "flix_test#{System.get_env("MIX_TEST_PARTITION")}",
pool: Ecto.Adapters.SQL.Sandbox,
pool_size: 10
pool_size: System.schedulers_online() * 2

# We don't run a server during test. If one is required,
# you can enable the server option below.
config :flix, FlixWeb.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 4002],
secret_key_base: "36x+Owok727HAPW0YsIMAqf6uF9/Rqpgzvg06aS+7+CGGs9QlkrQlPN5bB7QhlTv",
secret_key_base: "0tGKECPKVrlL6aWOZtMHm2MJZUwa7vhTz/EaK6YD2mgh2+HMNT+lpP6j1V7lc9+t",
server: false

# In test we don't send emails.
config :flix, Flix.Mailer, adapter: Swoosh.Adapters.Test

# Disable swoosh api client as it is only required for production adapters.
config :swoosh, :api_client, false

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

# Initialize plugs at runtime for faster test compilation
config :phoenix, :plug_init_mode, :runtime
Expand Down
Loading