Skip to content
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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"database"
],
"shutdownAction": "stopCompose",
"postCreateCommand": "pre-commit install --hook-type commit-msg",
"postCreateCommand": "pre-commit install",
"workspaceFolder": "/workspace",
"overrideCommand": true, // Hack while debugging
"customizations": {
Expand Down
34 changes: 3 additions & 31 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,8 @@ repos:

- repo: local
hooks:
- id: mix-openapispex-generate
name: 'elixir: mix openapi.spec.yaml'
entry: mix openapi.spec.yaml --spec BathLARPWeb.ApiSpec --start-app=false
- id: mix-precommit
name: 'elixir: mix precommit'
entry: mix precommit
language: system
pass_filenames: false
files: lib/bathlarp_web/.*\.ex$

- id: mix-test
name: 'elixir: mix test'
entry: mix test
language: system
pass_filenames: false
files: \.exs*$

- id: mix-format
name: 'elixir: mix format'
entry: mix format --check-formatted
language: system
files: \.exs*$

- id: mix-compile
name: 'elixir: mix compile'
entry: mix compile --force --warnings-as-errors
language: system
pass_filenames: false
files: \.ex$

- id: mix-credo
name: 'elixir: mix credo'
entry: mix credo
language: system
pass_filenames: false
files: \.exs*$
327 changes: 327 additions & 0 deletions AGENTS.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import Config
config :bathlarp,
namespace: BathLARP,
ecto_repos: [BathLARP.Repo],
generators: [binary_id: true]
generators: [timestamp_type: :utc_datetime, binary_id: true]

# Configures the endpoint
config :bathlarp, BathLARPWeb.Endpoint,
url: [host: "localhost"],
adapter: Bandit.PhoenixAdapter,
render_errors: [
formats: [json: BathLARPWeb.ErrorJSON],
layout: false
Expand All @@ -32,7 +33,7 @@ config :bathlarp, BathLARPWeb.Endpoint,
config :bathlarp, BathLARPWeb.PowMailer, adapter: Swoosh.Adapters.Local

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

Expand Down
4 changes: 2 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ config :bathlarp, BathLARP.Repo,
config :bathlarp, BathLARPWeb.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],
http: [ip: {127, 0, 0, 1}, port: String.to_integer(System.get_env("PORT") || "4000")],
check_origin: false,
code_reloader: true,
debug_errors: true,
Expand Down Expand Up @@ -53,7 +53,7 @@ config :bathlarp, BathLARPWeb.Endpoint,
config :bathlarp, dev_routes: true

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

# Set a higher stacktrace during development. Avoid configuring such
# in production as building large stacktraces may be expensive.
Expand Down
2 changes: 1 addition & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Config

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

# Disable Swoosh Local Memory Storage
config :swoosh, local: false
Expand Down
20 changes: 12 additions & 8 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ if config_env() == :prod do
# ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
# For machines with several cores, consider starting multiple pools of `pool_size`
# pool_count: 4,
socket_options: maybe_ipv6

# The secret key base is used to sign/encrypt cookies and other secrets.
Expand All @@ -51,12 +53,14 @@ if config_env() == :prod do
host = System.get_env("PHX_HOST") || "example.com"
port = String.to_integer(System.get_env("PORT") || "4000")

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

config :bathlarp, BathLARPWeb.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: port
Expand Down Expand Up @@ -87,8 +91,8 @@ if config_env() == :prod do
# "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:
# We also recommend setting `force_ssl` in your config/prod.exs,
# ensuring no data is ever sent via http, always redirecting to https:
#
# config :bathlarp, BathLARPWeb.Endpoint,
# force_ssl: [hsts: true]
Expand All @@ -98,18 +102,18 @@ if config_env() == :prod do
# ## Configuring the mailer
#
# In production you need to configure the mailer to use a different adapter.
# Also, you may need to configure the Swoosh API client of your choice if you
# are not using SMTP. Here is an example of the configuration:
# Here is an example configuration for Mailgun:
#
# config :bathlarp, BathLARP.Mailer,
# adapter: Swoosh.Adapters.Mailgun,
# api_key: System.get_env("MAILGUN_API_KEY"),
# domain: System.get_env("MAILGUN_DOMAIN")
#
# For this example you need include a HTTP client required by Swoosh API client.
# Swoosh supports Hackney and Finch out of the box:
# Most non-SMTP adapters require an API client. Swoosh supports Req, Hackney,
# and Finch out-of-the-box. This configuration is typically done at
# compile-time in your config/prod.exs:
#
# config :swoosh, :api_client, Swoosh.ApiClient.Hackney
# config :swoosh, :api_client, Swoosh.ApiClient.Req
#
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
end
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ config :bathlarp, BathLARP.Repo,
hostname: System.get_env("BATHLARP_DATABASE_HOST", "database"),
database: "bathlarp_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.
Expand Down
12 changes: 4 additions & 8 deletions lib/bathlarp/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ defmodule BathLARP.Application do
@impl true
def start(_type, _args) do
children = [
# Start the Telemetry supervisor
BathLARPWeb.Telemetry,
# Start the Ecto repository
BathLARP.Repo,
# Start the PubSub system
{DNSCluster, query: Application.get_env(:bathlarp, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: BathLARP.PubSub},
# Start Finch
{Finch, name: BathLARP.Finch},
# Start the Endpoint (http/https)
BathLARPWeb.Endpoint
# Start a worker by calling: BathLARP.Worker.start_link(arg)
# {BathLARP.Worker, arg}
# {BathLARP.Worker, arg},
# Start to serve requests, typically the last entry
BathLARPWeb.Endpoint
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand Down
9 changes: 4 additions & 5 deletions lib/bathlarp_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ defmodule BathLARPWeb do

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

import Plug.Conn
use Gettext, backend: BathLARPWeb.Gettext

import Plug.Conn

unquote(verified_routes())
end
end
Expand All @@ -64,7 +63,7 @@ defmodule BathLARPWeb do
end

@doc """
When used, dispatch to the appropriate controller/view/etc.
When used, dispatch to the appropriate controller/live_view/etc.
"""
defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, [])
Expand Down
11 changes: 7 additions & 4 deletions lib/bathlarp_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ defmodule BathLARPWeb.Endpoint do
same_site: "Lax"
]

socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
socket "/live", Phoenix.LiveView.Socket,
websocket: [connect_info: [session: @session_options]],
longpoll: [connect_info: [session: @session_options]]

# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phx.digest
# when deploying your static files in production.
# When code reloading is disabled (e.g., in production),
# the `gzip` option is enabled to serve compressed
# static files generated by running `phx.digest`.
plug Plug.Static,
at: "/",
from: :bathlarp,
gzip: false,
gzip: not code_reloading?,
only: BathLARPWeb.static_paths()

# Code reloading can be explicitly enabled under the
Expand Down
7 changes: 4 additions & 3 deletions lib/bathlarp_web/gettext.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ defmodule BathLARPWeb.Gettext do
@moduledoc """
A module providing Internationalization with a gettext-based API.

By using [Gettext](https://hexdocs.pm/gettext),
your module gains a set of macros for translations, for example:
By using [Gettext](https://hexdocs.pm/gettext), your module compiles translations
that you can use in your application. To use this Gettext backend module,
call `use Gettext` and pass it as an option:

import BathLARPWeb.Gettext
use Gettext, backend: BathLARPWeb.Gettext

# Simple translation
gettext("Here is the string to translate")
Expand Down
1 change: 1 addition & 0 deletions lib/bathlarp_web/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ defmodule BathLARPWeb.Telemetry do
summary("phoenix.socket_connected.duration",
unit: {:native, :millisecond}
),
sum("phoenix.socket_drain.count"),
summary("phoenix.channel_joined.duration",
unit: {:native, :millisecond}
),
Expand Down
40 changes: 29 additions & 11 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ defmodule BathLARP.MixProject do
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps()
deps: deps(),
listeners: [Phoenix.CodeReloader]
]
end

Expand All @@ -23,6 +24,12 @@ defmodule BathLARP.MixProject do
]
end

def cli do
[
preferred_envs: [precommit: :test]
]
end

# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
Expand All @@ -32,18 +39,21 @@ defmodule BathLARP.MixProject do
# Type `mix help deps` for examples and options.
defp deps do
[
{:phoenix, "~> 1.7.7"},
{:phoenix_ecto, "~> 4.4"},
{:ecto_sql, "~> 3.10"},
# Remove override when Pow supports latest Phoenix
{:phoenix, "~> 1.8.1", override: true},
{:phoenix_ecto, "~> 4.5"},
{:ecto_sql, "~> 3.13"},
{:postgrex, ">= 0.0.0"},
{:phoenix_live_dashboard, "~> 0.8.0"},
{:swoosh, "~> 1.3"},
{:finch, "~> 0.13"},
{:telemetry_metrics, "~> 0.6"},
{:phoenix_live_dashboard, "~> 0.8.3"},
{:swoosh, "~> 1.16"},
{:req, "~> 0.5"},
{:telemetry_metrics, "~> 1.0"},
{:telemetry_poller, "~> 1.0"},
{:gettext, "~> 0.20"},
{:gettext, "~> 0.26"},
{:jason, "~> 1.2"},
{:plug_cowboy, "~> 2.5"},
{:dns_cluster, "~> 0.2.0"},
{:bandit, "~> 1.5"},
# Custom deps
{:ecto_psql_extras, "~> 0.6"},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:pow, "~> 1.0.34"},
Expand All @@ -65,7 +75,15 @@ defmodule BathLARP.MixProject do
setup: ["deps.get", "ecto.setup"],
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"]
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
precommit: [
"compile --warning-as-errors",
"deps.unlock --unused",
"format",
"test",
"credo",
"openapi.spec.yaml --spec BathLARPWeb.ApiSpec --start-app=false"
]
]
end
end
Loading