diff --git a/.gitignore b/.gitignore index d3c7bc8..64faf31 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ erl_crash.dump *.ez /tmp/ -statusphere_elixir-*.tar +statusphere-*.tar /priv/static/assets/ /priv/static/cache_manifest.json npm-debug.log diff --git a/README.md b/README.md index d8db3d0..a4ad876 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,20 @@ -# StatusphereElixir +# Statusphere To start your Phoenix server: -* Run `mix setup` to install and setup dependencies -* Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server` +- Run `mix setup` to install and setup dependencies +- Start Phoenix endpoint with `mix phx.server` or inside IEx with + `iex -S mix phx.server` Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. -Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html). +Ready to run in production? Please +[check our deployment guides](https://hexdocs.pm/phoenix/deployment.html). ## Learn more -* Official website: https://www.phoenixframework.org/ -* Guides: https://hexdocs.pm/phoenix/overview.html -* Docs: https://hexdocs.pm/phoenix -* Forum: https://elixirforum.com/c/phoenix-forum -* Source: https://github.com/phoenixframework/phoenix +- Official website: https://www.phoenixframework.org/ +- Guides: https://hexdocs.pm/phoenix/overview.html +- Docs: https://hexdocs.pm/phoenix +- Forum: https://elixirforum.com/c/phoenix-forum +- Source: https://github.com/phoenixframework/phoenix diff --git a/assets/css/app.css b/assets/css/app.css index dbd07cf..3b86da7 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -4,7 +4,7 @@ @import "tailwindcss" source(none); @source "../css"; @source "../js"; -@source "../../lib/statusphere_elixir_web"; +@source "../../lib/statusphere_web"; /* A Tailwind plugin that makes "hero-#{ICON}" classes available. The heroicons installation itself is managed by your mix.exs */ @@ -100,6 +100,9 @@ @custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *)); /* Make LiveView wrapper divs transparent for layout */ -[data-phx-session], [data-phx-teleported-src] { display: contents } +[data-phx-session], +[data-phx-teleported-src] { + display: contents; +} /* This file is for your main application CSS */ diff --git a/assets/js/app.js b/assets/js/app.js index 8fa42cf..d1a2e23 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -18,33 +18,35 @@ // To load it, simply add a second `` to your `root.html.heex` file. // Include phoenix_html to handle method=PUT/DELETE in forms and buttons. -import "phoenix_html" +import "phoenix_html"; // Establish Phoenix Socket and LiveView configuration. -import {Socket} from "phoenix" -import {LiveSocket} from "phoenix_live_view" -import {hooks as colocatedHooks} from "phoenix-colocated/statusphere_elixir" -import topbar from "../vendor/topbar" +import { Socket } from "phoenix"; +import { LiveSocket } from "phoenix_live_view"; +import { hooks as colocatedHooks } from "phoenix-colocated/statusphere"; +import topbar from "../vendor/topbar"; -const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") +const csrfToken = document + .querySelector("meta[name='csrf-token']") + .getAttribute("content"); const liveSocket = new LiveSocket("/live", Socket, { longPollFallbackMs: 2500, - params: {_csrf_token: csrfToken}, - hooks: {...colocatedHooks}, -}) + params: { _csrf_token: csrfToken }, + hooks: { ...colocatedHooks }, +}); // Show progress bar on live navigation and form submits -topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"}) -window.addEventListener("phx:page-loading-start", _info => topbar.show(300)) -window.addEventListener("phx:page-loading-stop", _info => topbar.hide()) +topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" }); +window.addEventListener("phx:page-loading-start", (_info) => topbar.show(300)); +window.addEventListener("phx:page-loading-stop", (_info) => topbar.hide()); // connect if there are any LiveViews on the page -liveSocket.connect() +liveSocket.connect(); // expose liveSocket on window for web console debug logs and latency simulation: // >> liveSocket.enableDebug() // >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session // >> liveSocket.disableLatencySim() -window.liveSocket = liveSocket +window.liveSocket = liveSocket; // The lines below enable quality of life phoenix_live_reload // development features: @@ -53,31 +55,37 @@ window.liveSocket = liveSocket // 2. click on elements to jump to their definitions in your code editor // if (process.env.NODE_ENV === "development") { - window.addEventListener("phx:live_reload:attached", ({detail: reloader}) => { - // Enable server log streaming to client. - // Disable with reloader.disableServerLogs() - reloader.enableServerLogs() + window.addEventListener( + "phx:live_reload:attached", + ({ detail: reloader }) => { + // Enable server log streaming to client. + // Disable with reloader.disableServerLogs() + reloader.enableServerLogs(); - // Open configured PLUG_EDITOR at file:line of the clicked element's HEEx component - // - // * click with "c" key pressed to open at caller location - // * click with "d" key pressed to open at function component definition location - let keyDown - window.addEventListener("keydown", e => keyDown = e.key) - window.addEventListener("keyup", _e => keyDown = null) - window.addEventListener("click", e => { - if(keyDown === "c"){ - e.preventDefault() - e.stopImmediatePropagation() - reloader.openEditorAtCaller(e.target) - } else if(keyDown === "d"){ - e.preventDefault() - e.stopImmediatePropagation() - reloader.openEditorAtDef(e.target) - } - }, true) + // Open configured PLUG_EDITOR at file:line of the clicked element's HEEx component + // + // * click with "c" key pressed to open at caller location + // * click with "d" key pressed to open at function component definition location + let keyDown; + window.addEventListener("keydown", (e) => (keyDown = e.key)); + window.addEventListener("keyup", (_e) => (keyDown = null)); + window.addEventListener( + "click", + (e) => { + if (keyDown === "c") { + e.preventDefault(); + e.stopImmediatePropagation(); + reloader.openEditorAtCaller(e.target); + } else if (keyDown === "d") { + e.preventDefault(); + e.stopImmediatePropagation(); + reloader.openEditorAtDef(e.target); + } + }, + true + ); - window.liveReloader = reloader - }) + window.liveReloader = reloader; + } + ); } - diff --git a/config/config.exs b/config/config.exs index 39aad2d..f4bffb5 100644 --- a/config/config.exs +++ b/config/config.exs @@ -7,25 +7,25 @@ # General application configuration import Config -config :statusphere_elixir, - ecto_repos: [StatusphereElixir.Repo], +config :statusphere, + ecto_repos: [Statusphere.Repo], generators: [timestamp_type: :utc_datetime, binary_id: true] # Configure the endpoint -config :statusphere_elixir, StatusphereElixirWeb.Endpoint, +config :statusphere, StatusphereWeb.Endpoint, url: [host: "localhost"], adapter: Bandit.PhoenixAdapter, render_errors: [ - formats: [html: StatusphereElixirWeb.ErrorHTML, json: StatusphereElixirWeb.ErrorJSON], + formats: [html: StatusphereWeb.ErrorHTML, json: StatusphereWeb.ErrorJSON], layout: false ], - pubsub_server: StatusphereElixir.PubSub, + pubsub_server: Statusphere.PubSub, live_view: [signing_salt: "t+91lIqk"] # Configure esbuild (the version is required) config :esbuild, version: "0.25.4", - statusphere_elixir: [ + statusphere: [ args: ~w(js/app.js --bundle --target=es2022 --outdir=../priv/static/assets/js --external:/fonts/* --external:/images/* --alias:@=.), cd: Path.expand("../assets", __DIR__), @@ -35,7 +35,7 @@ config :esbuild, # Configure tailwind (the version is required) config :tailwind, version: "4.1.12", - statusphere_elixir: [ + statusphere: [ args: ~w( --input=assets/css/app.css --output=priv/static/assets/css/app.css @@ -57,6 +57,10 @@ config :logger, :default_formatter, # Use Jason for JSON parsing in Phoenix config :phoenix, :json_library, Jason +config :atex, Atex.OAuth, + scopes: ["transition:generic"], + key_id: "statusphere" + # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{config_env()}.exs" diff --git a/config/dev.exs b/config/dev.exs index fa95d85..753b4f2 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,8 +1,8 @@ import Config # Configure your database -config :statusphere_elixir, StatusphereElixir.Repo, - database: Path.expand("../statusphere_elixir_dev.db", __DIR__), +config :statusphere, Statusphere.Repo, + database: Path.expand("../statusphere_dev.db", __DIR__), pool_size: 5, stacktrace: true, show_sensitive_data_on_connection_error: true @@ -13,7 +13,7 @@ config :statusphere_elixir, StatusphereElixir.Repo, # The watchers configuration can be used to run external # watchers to your application. For example, we can use it # to bundle .js and .css sources. -config :statusphere_elixir, StatusphereElixirWeb.Endpoint, +config :statusphere, StatusphereWeb.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}], @@ -22,8 +22,8 @@ config :statusphere_elixir, StatusphereElixirWeb.Endpoint, debug_errors: true, secret_key_base: "YjHndGQyYIEkOsJtZzle8dUtbznbvM2CwGhF7NSoWxgSTIGpouNbVIND7cAmnWfB", watchers: [ - esbuild: {Esbuild, :install_and_run, [:statusphere_elixir, ~w(--sourcemap=inline --watch)]}, - tailwind: {Tailwind, :run, [:statusphere_elixir, ~w(--watch)]} + esbuild: {Esbuild, :install_and_run, [:statusphere, ~w(--sourcemap=inline --watch)]}, + tailwind: {Tailwind, :run, [:statusphere, ~w(--watch)]} ] # ## SSL Support @@ -50,20 +50,20 @@ config :statusphere_elixir, StatusphereElixirWeb.Endpoint, # different ports. # Reload browser tabs when matching files change. -config :statusphere_elixir, StatusphereElixirWeb.Endpoint, +config :statusphere, StatusphereWeb.Endpoint, live_reload: [ web_console_logger: true, patterns: [ # Static assets, except user uploads ~r"priv/static/(?!uploads/).*\.(js|css|png|jpeg|jpg|gif|svg)$", # Router, Controllers, LiveViews and LiveComponents - ~r"lib/statusphere_elixir_web/router\.ex$", - ~r"lib/statusphere_elixir_web/(controllers|live|components)/.*\.(ex|heex)$" + ~r"lib/statusphere_web/router\.ex$", + ~r"lib/statusphere_web/(controllers|live|components)/.*\.(ex|heex)$" ] ] # Enable dev routes for dashboard and mailbox -config :statusphere_elixir, dev_routes: true +config :statusphere, dev_routes: true # Do not include metadata nor timestamps in development logs config :logger, :default_formatter, format: "[$level] $message\n" @@ -82,3 +82,9 @@ config :phoenix_live_view, debug_attributes: true, # Enable helpful, but potentially expensive runtime checks enable_expensive_runtime_checks: true + +config :atex, Atex.OAuth, + base_url: "http://127.0.0.1:4000/oauth", + private_key: + "MHcCAQEEIGA8RFx1QUfvdVPD24SvBMS6a0X9fPYx6EPLHttG55ScoAoGCCqGSM49AwEHoUQDQgAEcGzUFa2vMqnevHI5R+QByCmHSCfVy7Uge3VcL5GPVL/tBMeoVizxZey3MUekIHZ981iXW8fTbntYJNXMi2hN5w==", + is_localhost: true diff --git a/config/prod.exs b/config/prod.exs index e3085f7..d2db1ee 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -5,13 +5,13 @@ import Config # 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 :statusphere_elixir, StatusphereElixirWeb.Endpoint, +config :statusphere, StatusphereWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json" # Force using SSL in production. This also sets the "strict-security-transport" header, # known as HSTS. If you have a health check endpoint, you may want to exclude it below. # Note `:force_ssl` is required to be set at compile-time. -config :statusphere_elixir, StatusphereElixirWeb.Endpoint, +config :statusphere, StatusphereWeb.Endpoint, force_ssl: [rewrite_on: [:x_forwarded_proto]], exclude: [ # paths: ["/health"], diff --git a/config/runtime.exs b/config/runtime.exs index 0c18c88..3d9cc50 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -12,15 +12,15 @@ import Config # 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/statusphere_elixir start +# PHX_SERVER=true bin/statusphere 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 :statusphere_elixir, StatusphereElixirWeb.Endpoint, server: true + config :statusphere, StatusphereWeb.Endpoint, server: true end -config :statusphere_elixir, StatusphereElixirWeb.Endpoint, +config :statusphere, StatusphereWeb.Endpoint, http: [port: String.to_integer(System.get_env("PORT", "4000"))] if config_env() == :prod do @@ -28,10 +28,10 @@ if config_env() == :prod do System.get_env("DATABASE_PATH") || raise """ environment variable DATABASE_PATH is missing. - For example: /etc/statusphere_elixir/statusphere_elixir.db + For example: /etc/statusphere/statusphere.db """ - config :statusphere_elixir, StatusphereElixir.Repo, + config :statusphere, Statusphere.Repo, database: database_path, pool_size: String.to_integer(System.get_env("POOL_SIZE") || "5") @@ -49,9 +49,9 @@ if config_env() == :prod do host = System.get_env("PHX_HOST") || "example.com" - config :statusphere_elixir, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY") + config :statusphere, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY") - config :statusphere_elixir, StatusphereElixirWeb.Endpoint, + config :statusphere, StatusphereWeb.Endpoint, url: [host: host, port: 443, scheme: "https"], http: [ # Enable IPv6 and bind on all interfaces. @@ -67,7 +67,7 @@ if config_env() == :prod do # To get SSL working, you will need to add the `https` key # to your endpoint configuration: # - # config :statusphere_elixir, StatusphereElixirWeb.Endpoint, + # config :statusphere, StatusphereWeb.Endpoint, # https: [ # ..., # port: 443, @@ -89,7 +89,7 @@ if config_env() == :prod do # We also recommend setting `force_ssl` in your config/prod.exs, # ensuring no data is ever sent via http, always redirecting to https: # - # config :statusphere_elixir, StatusphereElixirWeb.Endpoint, + # config :statusphere, StatusphereWeb.Endpoint, # force_ssl: [hsts: true] # # Check `Plug.SSL` for all available options in `force_ssl`. diff --git a/config/test.exs b/config/test.exs index 5e12370..752ba64 100644 --- a/config/test.exs +++ b/config/test.exs @@ -5,14 +5,14 @@ import Config # 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 :statusphere_elixir, StatusphereElixir.Repo, - database: Path.expand("../statusphere_elixir_test.db", __DIR__), +config :statusphere, Statusphere.Repo, + database: Path.expand("../statusphere_test.db", __DIR__), pool_size: 5, 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 :statusphere_elixir, StatusphereElixirWeb.Endpoint, +config :statusphere, StatusphereWeb.Endpoint, http: [ip: {127, 0, 0, 1}, port: 4002], secret_key_base: "AjDaXXlcrR04FEL+g7EV1+pKX7Fnvuhp63uWWK4I8zwKYmgReKy4WxqvdSNDdoT7", server: false diff --git a/lib/statusphere_elixir.ex b/lib/statusphere.ex similarity index 65% rename from lib/statusphere_elixir.ex rename to lib/statusphere.ex index 4b3ddd5..87572d3 100644 --- a/lib/statusphere_elixir.ex +++ b/lib/statusphere.ex @@ -1,6 +1,6 @@ -defmodule StatusphereElixir do +defmodule Statusphere do @moduledoc """ - StatusphereElixir keeps the contexts that define your domain + Statusphere keeps the contexts that define your domain and business logic. Contexts are also responsible for managing your data, regardless diff --git a/lib/statusphere_elixir/application.ex b/lib/statusphere/application.ex similarity index 53% rename from lib/statusphere_elixir/application.ex rename to lib/statusphere/application.ex index 3b09bc1..106f202 100644 --- a/lib/statusphere_elixir/application.ex +++ b/lib/statusphere/application.ex @@ -1,4 +1,4 @@ -defmodule StatusphereElixir.Application do +defmodule Statusphere.Application do # See https://hexdocs.pm/elixir/Application.html # for more information on OTP Applications @moduledoc false @@ -8,21 +8,21 @@ defmodule StatusphereElixir.Application do @impl true def start(_type, _args) do children = [ - StatusphereElixirWeb.Telemetry, - StatusphereElixir.Repo, + StatusphereWeb.Telemetry, + Statusphere.Repo, {Ecto.Migrator, - repos: Application.fetch_env!(:statusphere_elixir, :ecto_repos), skip: skip_migrations?()}, - {DNSCluster, query: Application.get_env(:statusphere_elixir, :dns_cluster_query) || :ignore}, - {Phoenix.PubSub, name: StatusphereElixir.PubSub}, - # Start a worker by calling: StatusphereElixir.Worker.start_link(arg) - # {StatusphereElixir.Worker, arg}, + repos: Application.fetch_env!(:statusphere, :ecto_repos), skip: skip_migrations?()}, + {DNSCluster, query: Application.get_env(:statusphere, :dns_cluster_query) || :ignore}, + {Phoenix.PubSub, name: Statusphere.PubSub}, + # Start a worker by calling: Statusphere.Worker.start_link(arg) + # {Statusphere.Worker, arg}, # Start to serve requests, typically the last entry - StatusphereElixirWeb.Endpoint + StatusphereWeb.Endpoint ] # See https://hexdocs.pm/elixir/Supervisor.html # for other strategies and supported options - opts = [strategy: :one_for_one, name: StatusphereElixir.Supervisor] + opts = [strategy: :one_for_one, name: Statusphere.Supervisor] Supervisor.start_link(children, opts) end @@ -30,7 +30,7 @@ defmodule StatusphereElixir.Application do # whenever the application is updated. @impl true def config_change(changed, _new, removed) do - StatusphereElixirWeb.Endpoint.config_change(changed, removed) + StatusphereWeb.Endpoint.config_change(changed, removed) :ok end diff --git a/lib/statusphere/repo.ex b/lib/statusphere/repo.ex new file mode 100644 index 0000000..98a7797 --- /dev/null +++ b/lib/statusphere/repo.ex @@ -0,0 +1,5 @@ +defmodule Statusphere.Repo do + use Ecto.Repo, + otp_app: :statusphere, + adapter: Ecto.Adapters.SQLite3 +end diff --git a/lib/statusphere_elixir/repo.ex b/lib/statusphere_elixir/repo.ex deleted file mode 100644 index ff7feb8..0000000 --- a/lib/statusphere_elixir/repo.ex +++ /dev/null @@ -1,5 +0,0 @@ -defmodule StatusphereElixir.Repo do - use Ecto.Repo, - otp_app: :statusphere_elixir, - adapter: Ecto.Adapters.SQLite3 -end diff --git a/lib/statusphere_elixir_web/controllers/page_controller.ex b/lib/statusphere_elixir_web/controllers/page_controller.ex deleted file mode 100644 index 5d2dbe9..0000000 --- a/lib/statusphere_elixir_web/controllers/page_controller.ex +++ /dev/null @@ -1,7 +0,0 @@ -defmodule StatusphereElixirWeb.PageController do - use StatusphereElixirWeb, :controller - - def home(conn, _params) do - render(conn, :home) - end -end diff --git a/lib/statusphere_elixir_web/controllers/page_html/home.html.heex b/lib/statusphere_elixir_web/controllers/page_html/home.html.heex deleted file mode 100644 index b107fd0..0000000 --- a/lib/statusphere_elixir_web/controllers/page_html/home.html.heex +++ /dev/null @@ -1,202 +0,0 @@ - - -
-
- -
-

- Phoenix Framework - - v{Application.spec(:phoenix, :vsn)} - -

- -
- -

- Peace of mind from prototype to production. -

-

- Build rich, interactive web applications quickly, with less code and fewer moving parts. Join our growing community of developers using Phoenix to craft APIs, HTML5 apps and more, for fun or at scale. -

- -
-
diff --git a/lib/statusphere_elixir_web.ex b/lib/statusphere_web.ex similarity index 85% rename from lib/statusphere_elixir_web.ex rename to lib/statusphere_web.ex index 8992fb4..2905c5f 100644 --- a/lib/statusphere_elixir_web.ex +++ b/lib/statusphere_web.ex @@ -1,12 +1,12 @@ -defmodule StatusphereElixirWeb do +defmodule StatusphereWeb do @moduledoc """ The entrypoint for defining your web interface, such as controllers, components, channels, and so on. This can be used in your application as: - use StatusphereElixirWeb, :controller - use StatusphereElixirWeb, :html + use StatusphereWeb, :controller + use StatusphereWeb, :html The definitions below will be executed for every controller, component, etc, so keep them short and clean, focused @@ -80,11 +80,11 @@ defmodule StatusphereElixirWeb do # HTML escaping functionality import Phoenix.HTML # Core UI components - import StatusphereElixirWeb.CoreComponents + import StatusphereWeb.CoreComponents # Common modules used in templates alias Phoenix.LiveView.JS - alias StatusphereElixirWeb.Layouts + alias StatusphereWeb.Layouts # Routes generation with the ~p sigil unquote(verified_routes()) @@ -94,9 +94,9 @@ defmodule StatusphereElixirWeb do def verified_routes do quote do use Phoenix.VerifiedRoutes, - endpoint: StatusphereElixirWeb.Endpoint, - router: StatusphereElixirWeb.Router, - statics: StatusphereElixirWeb.static_paths() + endpoint: StatusphereWeb.Endpoint, + router: StatusphereWeb.Router, + statics: StatusphereWeb.static_paths() end end diff --git a/lib/statusphere_elixir_web/components/core_components.ex b/lib/statusphere_web/components/core_components.ex similarity index 98% rename from lib/statusphere_elixir_web/components/core_components.ex rename to lib/statusphere_web/components/core_components.ex index 107ca63..d2cf804 100644 --- a/lib/statusphere_elixir_web/components/core_components.ex +++ b/lib/statusphere_web/components/core_components.ex @@ -1,4 +1,4 @@ -defmodule StatusphereElixirWeb.CoreComponents do +defmodule StatusphereWeb.CoreComponents do @moduledoc """ Provides core UI components. @@ -475,9 +475,9 @@ defmodule StatusphereElixirWeb.CoreComponents do # uncommenting and adjusting the following code: # if count = opts[:count] do - # Gettext.dngettext(StatusphereElixirWeb.Gettext, "errors", msg, msg, count, opts) + # Gettext.dngettext(StatusphereWeb.Gettext, "errors", msg, msg, count, opts) # else - # Gettext.dgettext(StatusphereElixirWeb.Gettext, "errors", msg, opts) + # Gettext.dgettext(StatusphereWeb.Gettext, "errors", msg, opts) # end Enum.reduce(opts, msg, fn {key, value}, acc -> diff --git a/lib/statusphere_elixir_web/components/layouts.ex b/lib/statusphere_web/components/layouts.ex similarity index 98% rename from lib/statusphere_elixir_web/components/layouts.ex rename to lib/statusphere_web/components/layouts.ex index 1c6c585..1ea30d3 100644 --- a/lib/statusphere_elixir_web/components/layouts.ex +++ b/lib/statusphere_web/components/layouts.ex @@ -1,9 +1,9 @@ -defmodule StatusphereElixirWeb.Layouts do +defmodule StatusphereWeb.Layouts do @moduledoc """ This module holds layouts and related functionality used by your application. """ - use StatusphereElixirWeb, :html + use StatusphereWeb, :html # Embed all files in layouts/* within this module. # The default root.html.heex file contains the HTML diff --git a/lib/statusphere_elixir_web/components/layouts/root.html.heex b/lib/statusphere_web/components/layouts/root.html.heex similarity index 94% rename from lib/statusphere_elixir_web/components/layouts/root.html.heex rename to lib/statusphere_web/components/layouts/root.html.heex index c515aa7..489d356 100644 --- a/lib/statusphere_elixir_web/components/layouts/root.html.heex +++ b/lib/statusphere_web/components/layouts/root.html.heex @@ -4,7 +4,7 @@ - <.live_title default="StatusphereElixir" suffix=" · Phoenix Framework"> + <.live_title default="Statusphere" suffix=" · Phoenix Framework"> {assigns[:page_title]} diff --git a/lib/statusphere_elixir_web/controllers/error_html.ex b/lib/statusphere_web/controllers/error_html.ex similarity index 71% rename from lib/statusphere_elixir_web/controllers/error_html.ex rename to lib/statusphere_web/controllers/error_html.ex index cc7a396..944dea3 100644 --- a/lib/statusphere_elixir_web/controllers/error_html.ex +++ b/lib/statusphere_web/controllers/error_html.ex @@ -1,17 +1,17 @@ -defmodule StatusphereElixirWeb.ErrorHTML do +defmodule StatusphereWeb.ErrorHTML do @moduledoc """ This module is invoked by your endpoint in case of errors on HTML requests. See config/config.exs. """ - use StatusphereElixirWeb, :html + use StatusphereWeb, :html # If you want to customize your error pages, # uncomment the embed_templates/1 call below # and add pages to the error directory: # - # * lib/statusphere_elixir_web/controllers/error_html/404.html.heex - # * lib/statusphere_elixir_web/controllers/error_html/500.html.heex + # * lib/statusphere_web/controllers/error_html/404.html.heex + # * lib/statusphere_web/controllers/error_html/500.html.heex # # embed_templates "error_html/*" diff --git a/lib/statusphere_elixir_web/controllers/error_json.ex b/lib/statusphere_web/controllers/error_json.ex similarity index 93% rename from lib/statusphere_elixir_web/controllers/error_json.ex rename to lib/statusphere_web/controllers/error_json.ex index 7a0e672..07596a2 100644 --- a/lib/statusphere_elixir_web/controllers/error_json.ex +++ b/lib/statusphere_web/controllers/error_json.ex @@ -1,4 +1,4 @@ -defmodule StatusphereElixirWeb.ErrorJSON do +defmodule StatusphereWeb.ErrorJSON do @moduledoc """ This module is invoked by your endpoint in case of errors on JSON requests. diff --git a/lib/statusphere_web/controllers/page_controller.ex b/lib/statusphere_web/controllers/page_controller.ex new file mode 100644 index 0000000..ebd9aec --- /dev/null +++ b/lib/statusphere_web/controllers/page_controller.ex @@ -0,0 +1,7 @@ +defmodule StatusphereWeb.PageController do + use StatusphereWeb, :controller + + def home(conn, _params) do + render(conn, :home) + end +end diff --git a/lib/statusphere_elixir_web/controllers/page_html.ex b/lib/statusphere_web/controllers/page_html.ex similarity index 69% rename from lib/statusphere_elixir_web/controllers/page_html.ex rename to lib/statusphere_web/controllers/page_html.ex index b3fcaca..e339931 100644 --- a/lib/statusphere_elixir_web/controllers/page_html.ex +++ b/lib/statusphere_web/controllers/page_html.ex @@ -1,10 +1,10 @@ -defmodule StatusphereElixirWeb.PageHTML do +defmodule StatusphereWeb.PageHTML do @moduledoc """ This module contains pages rendered by PageController. See the `page_html` directory for all templates available. """ - use StatusphereElixirWeb, :html + use StatusphereWeb, :html embed_templates "page_html/*" end diff --git a/lib/statusphere_web/controllers/page_html/home.html.heex b/lib/statusphere_web/controllers/page_html/home.html.heex new file mode 100644 index 0000000..97a48f5 --- /dev/null +++ b/lib/statusphere_web/controllers/page_html/home.html.heex @@ -0,0 +1,3 @@ + +
hello
+
\ No newline at end of file diff --git a/lib/statusphere_elixir_web/endpoint.ex b/lib/statusphere_web/endpoint.ex similarity index 82% rename from lib/statusphere_elixir_web/endpoint.ex rename to lib/statusphere_web/endpoint.ex index 2e016a6..ddb15f9 100644 --- a/lib/statusphere_elixir_web/endpoint.ex +++ b/lib/statusphere_web/endpoint.ex @@ -1,12 +1,12 @@ -defmodule StatusphereElixirWeb.Endpoint do - use Phoenix.Endpoint, otp_app: :statusphere_elixir +defmodule StatusphereWeb.Endpoint do + use Phoenix.Endpoint, otp_app: :statusphere # The session will be stored in the cookie and signed, # this means its contents can be read but not tampered with. # Set :encryption_salt if you would also like to encrypt it. @session_options [ store: :cookie, - key: "_statusphere_elixir_key", + key: "_statusphere_key", signing_salt: "zbKtWcZI", same_site: "Lax" ] @@ -22,9 +22,9 @@ defmodule StatusphereElixirWeb.Endpoint do # static files generated by running `phx.digest`. plug Plug.Static, at: "/", - from: :statusphere_elixir, + from: :statusphere, gzip: not code_reloading?, - only: StatusphereElixirWeb.static_paths(), + only: StatusphereWeb.static_paths(), raise_on_missing_only: code_reloading? # Code reloading can be explicitly enabled under the @@ -33,7 +33,7 @@ defmodule StatusphereElixirWeb.Endpoint do socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket plug Phoenix.LiveReloader plug Phoenix.CodeReloader - plug Phoenix.Ecto.CheckRepoStatus, otp_app: :statusphere_elixir + plug Phoenix.Ecto.CheckRepoStatus, otp_app: :statusphere end plug Phoenix.LiveDashboard.RequestLogger, @@ -51,5 +51,5 @@ defmodule StatusphereElixirWeb.Endpoint do plug Plug.MethodOverride plug Plug.Head plug Plug.Session, @session_options - plug StatusphereElixirWeb.Router + plug StatusphereWeb.Router end diff --git a/lib/statusphere_elixir_web/router.ex b/lib/statusphere_web/router.ex similarity index 64% rename from lib/statusphere_elixir_web/router.ex rename to lib/statusphere_web/router.ex index 49eba59..5d910f2 100644 --- a/lib/statusphere_elixir_web/router.ex +++ b/lib/statusphere_web/router.ex @@ -1,11 +1,11 @@ -defmodule StatusphereElixirWeb.Router do - use StatusphereElixirWeb, :router +defmodule StatusphereWeb.Router do + use StatusphereWeb, :router pipeline :browser do plug :accepts, ["html"] plug :fetch_session plug :fetch_live_flash - plug :put_root_layout, html: {StatusphereElixirWeb.Layouts, :root} + plug :put_root_layout, html: {StatusphereWeb.Layouts, :root} plug :protect_from_forgery plug :put_secure_browser_headers end @@ -14,19 +14,21 @@ defmodule StatusphereElixirWeb.Router do plug :accepts, ["json"] end - scope "/", StatusphereElixirWeb do + scope "/", StatusphereWeb do pipe_through :browser get "/", PageController, :home end + forward "/oauth", Atex.OAuth.Plug, callback: {__MODULE__, :oauth_callback, []} + # Other scopes may use custom stacks. - # scope "/api", StatusphereElixirWeb do + # scope "/api", StatusphereWeb do # pipe_through :api # end # Enable LiveDashboard in development - if Application.compile_env(:statusphere_elixir, :dev_routes) do + if Application.compile_env(:statusphere, :dev_routes) do # If you want to use the LiveDashboard in production, you should put # it behind authentication and allow only admins to access it. # If your application does not have an admins-only section yet, @@ -37,7 +39,11 @@ defmodule StatusphereElixirWeb.Router do scope "/dev" do pipe_through :browser - live_dashboard "/dashboard", metrics: StatusphereElixirWeb.Telemetry + live_dashboard "/dashboard", metrics: StatusphereWeb.Telemetry end end + + def oauth_callback(conn) do + redirect(conn, to: "/") + end end diff --git a/lib/statusphere_elixir_web/telemetry.ex b/lib/statusphere_web/telemetry.ex similarity index 87% rename from lib/statusphere_elixir_web/telemetry.ex rename to lib/statusphere_web/telemetry.ex index 5a7d7bd..45a9e7f 100644 --- a/lib/statusphere_elixir_web/telemetry.ex +++ b/lib/statusphere_web/telemetry.ex @@ -1,4 +1,4 @@ -defmodule StatusphereElixirWeb.Telemetry do +defmodule StatusphereWeb.Telemetry do use Supervisor import Telemetry.Metrics @@ -53,23 +53,23 @@ defmodule StatusphereElixirWeb.Telemetry do ), # Database Metrics - summary("statusphere_elixir.repo.query.total_time", + summary("statusphere.repo.query.total_time", unit: {:native, :millisecond}, description: "The sum of the other measurements" ), - summary("statusphere_elixir.repo.query.decode_time", + summary("statusphere.repo.query.decode_time", unit: {:native, :millisecond}, description: "The time spent decoding the data received from the database" ), - summary("statusphere_elixir.repo.query.query_time", + summary("statusphere.repo.query.query_time", unit: {:native, :millisecond}, description: "The time spent executing the query" ), - summary("statusphere_elixir.repo.query.queue_time", + summary("statusphere.repo.query.queue_time", unit: {:native, :millisecond}, description: "The time spent waiting for a database connection" ), - summary("statusphere_elixir.repo.query.idle_time", + summary("statusphere.repo.query.idle_time", unit: {:native, :millisecond}, description: "The time the connection spent waiting before being checked out for the query" @@ -87,7 +87,7 @@ defmodule StatusphereElixirWeb.Telemetry do [ # A module, function and arguments to be invoked periodically. # This function must call :telemetry.execute/3 and a metric must be added above. - # {StatusphereElixirWeb, :count_users, []} + # {StatusphereWeb, :count_users, []} ] end end diff --git a/mix.exs b/mix.exs index 477240c..74d8a72 100644 --- a/mix.exs +++ b/mix.exs @@ -1,9 +1,9 @@ -defmodule StatusphereElixir.MixProject do +defmodule Statusphere.MixProject do use Mix.Project def project do [ - app: :statusphere_elixir, + app: :statusphere, version: "0.1.0", elixir: "~> 1.15", elixirc_paths: elixirc_paths(Mix.env()), @@ -20,7 +20,7 @@ defmodule StatusphereElixir.MixProject do # Type `mix help compile.app` for more information. def application do [ - mod: {StatusphereElixir.Application, []}, + mod: {Statusphere.Application, []}, extra_applications: [:logger, :runtime_tools] ] end @@ -63,7 +63,9 @@ defmodule StatusphereElixir.MixProject do {:jason, "~> 1.2"}, {:dns_cluster, "~> 0.2.0"}, {:bandit, "~> 1.5"}, - {:atex, "~> 0.6"}, + # {:atex, "~> 0.6"}, + {:atex, + git: "https://github.com/cometsh/atex.git", ref: "2cc3686d47e30118ac8ac2d48cdc135a13da9163"}, {:drinkup, "~> 0.1"}, {:typedstruct, "~> 0.5"} ] @@ -85,10 +87,10 @@ defmodule StatusphereElixir.MixProject do # "tailwind.install --if-missing", "esbuild.install --if-missing" ], - "assets.build": ["compile", "tailwind statusphere_elixir", "esbuild statusphere_elixir"], + "assets.build": ["compile", "tailwind statusphere", "esbuild statusphere"], "assets.deploy": [ - "tailwind statusphere_elixir --minify", - "esbuild statusphere_elixir --minify", + "tailwind statusphere --minify", + "esbuild statusphere --minify", "phx.digest" ], precommit: ["compile --warnings-as-errors", "deps.unlock --unused", "format", "test"] diff --git a/mix.lock b/mix.lock index b66a9d3..8de1958 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,5 @@ %{ - "atex": {:hex, :atex, "0.6.0", "a02f3c1b3ef04d8cd30243a05fc3629929c66d826e1d6a7e9d4ec6076ac89aea", [:mix], [{:ex_cldr, "~> 2.42", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:jose, "~> 1.11", [hex: :jose, repo: "hexpm", optional: false]}, {:multiformats_ex, "~> 0.2", [hex: :multiformats_ex, repo: "hexpm", optional: false]}, {:peri, "~> 0.6", [hex: :peri, repo: "hexpm", optional: false]}, {:plug, "~> 1.18", [hex: :plug, repo: "hexpm", optional: false]}, {:recase, "~> 0.5", [hex: :recase, repo: "hexpm", optional: false]}, {:req, "~> 0.5", [hex: :req, repo: "hexpm", optional: false]}, {:typedstruct, "~> 0.5", [hex: :typedstruct, repo: "hexpm", optional: false]}], "hexpm", "a3615e361e1e1b2887910834b3ede88680a02e4d585243ea90d0a6394f688aa2"}, + "atex": {:git, "https://github.com/cometsh/atex.git", "2cc3686d47e30118ac8ac2d48cdc135a13da9163", [ref: "2cc3686d47e30118ac8ac2d48cdc135a13da9163"]}, "bandit": {:hex, :bandit, "1.9.0", "6dc1ff2c30948dfecf32db574cc3447c7b9d70e0b61140098df3818870b01b76", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.18", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "2538aaa1663b40ca9cbd8ca1f8a540cb49e5baf34c6ffef068369cc45f9146f2"}, "car": {:hex, :car, "0.1.1", "a5bc4c5c1be96eab437634b3c0ccad1fe17b5e3d68c22a4031241ae1345aebd4", [:mix], [{:cbor, "~> 1.0.0", [hex: :cbor, repo: "hexpm", optional: false]}, {:typedstruct, "~> 0.5", [hex: :typedstruct, repo: "hexpm", optional: false]}, {:varint, "~> 1.4", [hex: :varint, repo: "hexpm", optional: false]}], "hexpm", "f895dda8123d04dd336db5a2bf0d0b47f4559cd5383f83fcca0700c1b45bfb6a"}, "cbor": {:hex, :cbor, "1.0.1", "39511158e8ea5a57c1fcb9639aaa7efde67129678fee49ebbda780f6f24959b0", [:mix], [], "hexpm", "5431acbe7a7908f17f6a9cd43311002836a34a8ab01876918d8cfb709cd8b6a2"}, diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index 8851c57..d727035 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -5,7 +5,7 @@ # Inside the script, you can read and write to any of your # repositories directly: # -# StatusphereElixir.Repo.insert!(%StatusphereElixir.SomeSchema{}) +# Statusphere.Repo.insert!(%Statusphere.SomeSchema{}) # # We recommend using the bang functions (`insert!`, `update!` # and so on) as they will fail if something goes wrong. diff --git a/test/statusphere_elixir_web/controllers/error_html_test.exs b/test/statusphere_elixir_web/controllers/error_html_test.exs index 226b4c1..091077f 100644 --- a/test/statusphere_elixir_web/controllers/error_html_test.exs +++ b/test/statusphere_elixir_web/controllers/error_html_test.exs @@ -1,14 +1,15 @@ -defmodule StatusphereElixirWeb.ErrorHTMLTest do - use StatusphereElixirWeb.ConnCase, async: true +defmodule StatusphereWeb.ErrorHTMLTest do + use StatusphereWeb.ConnCase, async: true # Bring render_to_string/4 for testing custom views import Phoenix.Template, only: [render_to_string: 4] test "renders 404.html" do - assert render_to_string(StatusphereElixirWeb.ErrorHTML, "404", "html", []) == "Not Found" + assert render_to_string(StatusphereWeb.ErrorHTML, "404", "html", []) == "Not Found" end test "renders 500.html" do - assert render_to_string(StatusphereElixirWeb.ErrorHTML, "500", "html", []) == "Internal Server Error" + assert render_to_string(StatusphereWeb.ErrorHTML, "500", "html", []) == + "Internal Server Error" end end diff --git a/test/statusphere_elixir_web/controllers/error_json_test.exs b/test/statusphere_elixir_web/controllers/error_json_test.exs index 5b43b12..a0daaab 100644 --- a/test/statusphere_elixir_web/controllers/error_json_test.exs +++ b/test/statusphere_elixir_web/controllers/error_json_test.exs @@ -1,12 +1,12 @@ -defmodule StatusphereElixirWeb.ErrorJSONTest do - use StatusphereElixirWeb.ConnCase, async: true +defmodule StatusphereWeb.ErrorJSONTest do + use StatusphereWeb.ConnCase, async: true test "renders 404" do - assert StatusphereElixirWeb.ErrorJSON.render("404.json", %{}) == %{errors: %{detail: "Not Found"}} + assert StatusphereWeb.ErrorJSON.render("404.json", %{}) == %{errors: %{detail: "Not Found"}} end test "renders 500" do - assert StatusphereElixirWeb.ErrorJSON.render("500.json", %{}) == + assert StatusphereWeb.ErrorJSON.render("500.json", %{}) == %{errors: %{detail: "Internal Server Error"}} end end diff --git a/test/statusphere_elixir_web/controllers/page_controller_test.exs b/test/statusphere_elixir_web/controllers/page_controller_test.exs index c584c49..72852f7 100644 --- a/test/statusphere_elixir_web/controllers/page_controller_test.exs +++ b/test/statusphere_elixir_web/controllers/page_controller_test.exs @@ -1,5 +1,5 @@ -defmodule StatusphereElixirWeb.PageControllerTest do - use StatusphereElixirWeb.ConnCase +defmodule StatusphereWeb.PageControllerTest do + use StatusphereWeb.ConnCase test "GET /", %{conn: conn} do conn = get(conn, ~p"/") diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 892742d..1671e9a 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -1,4 +1,4 @@ -defmodule StatusphereElixirWeb.ConnCase do +defmodule StatusphereWeb.ConnCase do @moduledoc """ This module defines the test case to be used by tests that require setting up a connection. @@ -11,7 +11,7 @@ defmodule StatusphereElixirWeb.ConnCase do we enable the SQL sandbox, so changes done to the database are reverted at the end of every test. If you are using PostgreSQL, you can even run database tests asynchronously - by setting `use StatusphereElixirWeb.ConnCase, async: true`, although + by setting `use StatusphereWeb.ConnCase, async: true`, although this option is not recommended for other databases. """ @@ -20,19 +20,19 @@ defmodule StatusphereElixirWeb.ConnCase do using do quote do # The default endpoint for testing - @endpoint StatusphereElixirWeb.Endpoint + @endpoint StatusphereWeb.Endpoint - use StatusphereElixirWeb, :verified_routes + use StatusphereWeb, :verified_routes # Import conveniences for testing with connections import Plug.Conn import Phoenix.ConnTest - import StatusphereElixirWeb.ConnCase + import StatusphereWeb.ConnCase end end setup tags do - StatusphereElixir.DataCase.setup_sandbox(tags) + Statusphere.DataCase.setup_sandbox(tags) {:ok, conn: Phoenix.ConnTest.build_conn()} end end diff --git a/test/support/data_case.ex b/test/support/data_case.ex index c4c26e1..29a5ec7 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -1,4 +1,4 @@ -defmodule StatusphereElixir.DataCase do +defmodule Statusphere.DataCase do @moduledoc """ This module defines the setup for tests requiring access to the application's data layer. @@ -10,7 +10,7 @@ defmodule StatusphereElixir.DataCase do we enable the SQL sandbox, so changes done to the database are reverted at the end of every test. If you are using PostgreSQL, you can even run database tests asynchronously - by setting `use StatusphereElixir.DataCase, async: true`, although + by setting `use Statusphere.DataCase, async: true`, although this option is not recommended for other databases. """ @@ -18,17 +18,17 @@ defmodule StatusphereElixir.DataCase do using do quote do - alias StatusphereElixir.Repo + alias Statusphere.Repo import Ecto import Ecto.Changeset import Ecto.Query - import StatusphereElixir.DataCase + import Statusphere.DataCase end end setup tags do - StatusphereElixir.DataCase.setup_sandbox(tags) + Statusphere.DataCase.setup_sandbox(tags) :ok end @@ -36,7 +36,7 @@ defmodule StatusphereElixir.DataCase do Sets up the sandbox based on the test tags. """ def setup_sandbox(tags) do - pid = Ecto.Adapters.SQL.Sandbox.start_owner!(StatusphereElixir.Repo, shared: not tags[:async]) + pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Statusphere.Repo, shared: not tags[:async]) on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end) end diff --git a/test/test_helper.exs b/test/test_helper.exs index 8c28574..9174297 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,2 +1,2 @@ ExUnit.start() -Ecto.Adapters.SQL.Sandbox.mode(StatusphereElixir.Repo, :manual) +Ecto.Adapters.SQL.Sandbox.mode(Statusphere.Repo, :manual)