From 8951df42824420cae2464e77f17c63a7651f2d96 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 15 Jun 2026 16:27:54 +0200 Subject: [PATCH] set up apps/csys example application (instead of projects/demo) --- apps/csys/config/config.exs | 20 +++++++++++++ {projects/demo => apps/csys}/config/dev.exs | 3 +- {projects/demo => apps/csys}/config/prod.exs | 0 apps/csys/config/runtime.exs | 4 +++ .../demo => apps/csys}/lib/application.ex | 7 +++-- apps/csys/lib/server/endpoint.ex | 19 ++++++++++++ {projects/demo => apps/csys}/mix.exs | 6 ++-- {projects/demo => apps/csys}/mix.lock | 12 ++++++++ apps/csys/priv/static/docs | 1 + apps/csys/priv/static/favicon.ico | Bin 0 -> 152 bytes apps/csys/priv/static/robots.txt | 5 ++++ config/config.exs | 2 +- lib/web/server/error_json.ex | 28 ++++++++++++++++++ lib/web/server/router.ex | 2 +- mix.exs | 2 +- projects/demo/config/config.exs | 10 ------- projects/demo/config/test.exs | 9 ------ 17 files changed, 101 insertions(+), 29 deletions(-) create mode 100644 apps/csys/config/config.exs rename {projects/demo => apps/csys}/config/dev.exs (59%) rename {projects/demo => apps/csys}/config/prod.exs (100%) create mode 100644 apps/csys/config/runtime.exs rename {projects/demo => apps/csys}/lib/application.ex (68%) create mode 100644 apps/csys/lib/server/endpoint.ex rename {projects/demo => apps/csys}/mix.exs (79%) rename {projects/demo => apps/csys}/mix.lock (53%) create mode 120000 apps/csys/priv/static/docs create mode 100644 apps/csys/priv/static/favicon.ico create mode 100644 apps/csys/priv/static/robots.txt create mode 100644 lib/web/server/error_json.ex delete mode 100644 projects/demo/config/config.exs delete mode 100644 projects/demo/config/test.exs diff --git a/apps/csys/config/config.exs b/apps/csys/config/config.exs new file mode 100644 index 0000000..45759da --- /dev/null +++ b/apps/csys/config/config.exs @@ -0,0 +1,20 @@ +# scopes: basic config file + +import Config + +config :logger, :default_formatter, + format: "$date $time [$level] $metadata $message\n", + colors: [enabled: false], + metadata: [:mfa, :pid] + +config :scopes_csys, Scopes.CSys.Server.Endpoint, + url: [host: "localhost"], + adapter: Bandit.PhoenixAdapter, + render_errors: [ + formats: [json: Scopes.Web.Server.ErrorJSON], + layout: false + ], + #pubsub_server: Scopes.Web.Server.PubSub, + live_view: [signing_salt: "3Jtdea8i"] + +import_config "#{config_env()}.exs" diff --git a/projects/demo/config/dev.exs b/apps/csys/config/dev.exs similarity index 59% rename from projects/demo/config/dev.exs rename to apps/csys/config/dev.exs index a591d70..644852b 100644 --- a/projects/demo/config/dev.exs +++ b/apps/csys/config/dev.exs @@ -3,10 +3,11 @@ import Config config :logger, :default_handler, + level: System.get_env("SCOPES_LOG_LEVEL", "info") |> String.to_atom, config: [ file: ~c"log/scopes_dev.log" ] -config :scopes_app, Scopes.Web.Server.Endpoint, +config :scopes_csys, Scopes.CSys.Server.Endpoint, http: [ip: {127, 0, 0, 1}, port: 8800] diff --git a/projects/demo/config/prod.exs b/apps/csys/config/prod.exs similarity index 100% rename from projects/demo/config/prod.exs rename to apps/csys/config/prod.exs diff --git a/apps/csys/config/runtime.exs b/apps/csys/config/runtime.exs new file mode 100644 index 0000000..739120b --- /dev/null +++ b/apps/csys/config/runtime.exs @@ -0,0 +1,4 @@ +import Config + +config :scopes, Scopes.Web.Server.Endpoint, server: true + diff --git a/projects/demo/lib/application.ex b/apps/csys/lib/application.ex similarity index 68% rename from projects/demo/lib/application.ex rename to apps/csys/lib/application.ex index e616a74..09e0e2c 100644 --- a/projects/demo/lib/application.ex +++ b/apps/csys/lib/application.ex @@ -1,4 +1,4 @@ -defmodule Scopes.Demo.Application do +defmodule Scopes.CSys.Application do use Application alias Scopes.Util @@ -9,10 +9,11 @@ defmodule Scopes.Demo.Application do @impl true def start(type, args) do - IO.puts("Hello World") + IO.puts("Hello CSys") Logger.info(Util.show [type, args]) children = [ - Scopes.Web.Server.Endpoint + #Scopes.Web.Server.Endpoint + Scopes.CSys.Server.Endpoint ] opts = [strategy: :one_for_one, name: Scopes.Supervisor] Supervisor.start_link(children, opts) diff --git a/apps/csys/lib/server/endpoint.ex b/apps/csys/lib/server/endpoint.ex new file mode 100644 index 0000000..bba7590 --- /dev/null +++ b/apps/csys/lib/server/endpoint.ex @@ -0,0 +1,19 @@ +defmodule Scopes.CSys.Server.Endpoint do + use Phoenix.Endpoint, otp_app: :scopes_csys + + plug Plug.Static, + at: "/", + from: :scopes_csys, + gzip: not code_reloading?, + only: Scopes.Web.Server.static_paths(), + raise_on_missing_only: code_reloading? + + plug Plug.RequestId + + plug Plug.Parsers, + parsers: [:urlencoded, :multipart, :json], + pass: ["*/*"], + json_decoder: Phoenix.json_library() + + plug Scopes.Web.Server.Router +end diff --git a/projects/demo/mix.exs b/apps/csys/mix.exs similarity index 79% rename from projects/demo/mix.exs rename to apps/csys/mix.exs index 4884d87..98d7cb3 100644 --- a/projects/demo/mix.exs +++ b/apps/csys/mix.exs @@ -1,9 +1,9 @@ -defmodule Scopes.DemoProject do +defmodule Scopes.CSys.Project do use Mix.Project def project do [ - app: :scopes_app, + app: :scopes_csys, version: "0.1.0", elixir: "~> 1.18", start_permanent: Mix.env() == :prod, @@ -14,7 +14,7 @@ defmodule Scopes.DemoProject do # Run "mix help compile.app" to learn about applications. def application do [ - mod: {Scopes.Demo.Application, []}, + mod: {Scopes.CSys.Application, []}, extra_applications: [:logger, :runtime_tools] ] end diff --git a/projects/demo/mix.lock b/apps/csys/mix.lock similarity index 53% rename from projects/demo/mix.lock rename to apps/csys/mix.lock index 6c1c4e4..fdc2ebc 100644 --- a/projects/demo/mix.lock +++ b/apps/csys/mix.lock @@ -1,13 +1,25 @@ %{ "bandit": {:hex, :bandit, "1.12.0", "6c5214daa2469644ac4ab0113b98abc24f75e348378e6a974c6343b3e5da22ef", [: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.5", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "45dac82dc86f45cf4a196dee9cc5a8b791d9c9469d996055f055e6ee36c66e20"}, + "cowboy": {:hex, :cowboy, "2.16.1", "fa04080b602ff25c40a7700f2dc0152dbc1ba26b42093ae0fa9bb7a337d5a242", [:make, :rebar3], [{:cowlib, ">= 2.16.0 and < 3.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, ">= 1.8.0 and < 3.0.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "b8ea4dd317a043e3177ec840cfa3bcb47cfb41035d3abb24d954dc7d51def399"}, + "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, + "cowlib": {:hex, :cowlib, "2.17.1", "3e6053016d1ab245730f0af688755476dcedb1c25ed8fb5751f59a2bfdc0c9af", [:make, :rebar3], [], "hexpm", "ff08bd17e6dd931445b18af77315b9b5fe052407110964ad2588c686b57b5e3f"}, + "db_connection": {:hex, :db_connection, "2.10.1", "d5465f6bcc125c1b8981c1dbf23c193ca16f446ec0b25832dc174f74f18be510", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "18ed94c6e627b4bf452dbd4df61b69a35a1e768525140bc1917b7a685026a6a3"}, + "decimal": {:hex, :decimal, "3.1.1", "430d87b04011ce6cbd4fd205be758311a81f87d552d40904abd00f015935b1d0", [:mix], [], "hexpm", "c5f25f2ced74a0587d03e6023f595db8e924c9d3922c8c8ffd9edfc4498cf1f6"}, + "ecto": {:hex, :ecto, "3.14.0", "2fa64521eebfcb2670d907a86e4ad947290e9933706bb315e6fb5c21b172cb26", [:mix], [{:decimal, "~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "130d69ffb4285f9ce4792b65dfbb994fd13ea4cbc3cbea2524b199aa3de84af3"}, + "ecto_sql": {:hex, :ecto_sql, "3.14.0", "06446ab8410d2f85bfbb80857ee224ab3b693700cbb38f6535d507449a627b2e", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.14.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.8", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f4d8d36faf294c9417b5a37ec7ac8217ee2abdef5fcf197ba690f361548d3949"}, "hpax": {:hex, :hpax, "1.0.3", "ed67ef51ad4df91e75cc6a1494f851850c0bd98ebc0be6e81b026e765ee535aa", [:mix], [], "hexpm", "8eab6e1cfa8d5918c2ce4ba43588e894af35dbd8e91e6e55c817bca5847df34a"}, + "jason": {:hex, :jason, "1.4.5", "2e3a008590b0b8d7388c20293e9dcc9cf3e5d642fd2a114e4cbbb52e595d940a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b0c823996102bcd0239b3c2444eb00409b72f6a140c1950bc8b457d836b30684"}, "mime": {:hex, :mime, "2.0.7", "b8d739037be7cd402aee1ba0306edfdef982687ee7e9859bee6198c1e7e2f128", [:mix], [], "hexpm", "6171188e399ee16023ffc5b76ce445eb6d9672e2e241d2df6050f3c771e80ccd"}, "phoenix": {:hex, :phoenix, "1.8.7", "d8d755b4ff4b449f610223dd706b4ae64155cb720d3dc09c706c079ecea189e4", [:mix], [{:bandit, "~> 1.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "47352f72d6ab31009ef77516b1b3a14745be97b54061fd458031b9d8294869d5"}, + "phoenix_ecto": {:hex, :phoenix_ecto, "4.7.0", "75c4b9dfb3efdc42aec2bd5f8bccd978aca0651dbcbc7a3f362ea5d9d43153c6", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.1", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "1d75011e4254cb4ddf823e81823a9629559a1be93b4321a6a5f11a5306fbf4cc"}, "phoenix_html": {:hex, :phoenix_html, "4.3.0", "d3577a5df4b6954cd7890c84d955c470b5310bb49647f0a114a6eeecc850f7ad", [:mix], [], "hexpm", "3eaa290a78bab0f075f791a46a981bbe769d94bc776869f4f3063a14f30497ad"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.2.0", "ff3a5616e1bed6804de7773b92cbccfc0b0f473faf1f63d7daf1206c7aeaaa6f", [:mix], [], "hexpm", "adc313a5bf7136039f63cfd9668fde73bba0765e0614cba80c06ac9460ff3e96"}, "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, "plug": {:hex, :plug, "1.19.2", "e4950525b22c6789dfb38a3f95d47171ba159da3fc5a33be9643b43d5e8adb98", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b6fce20a56af5e60fa5dfecf3f907bb98ec981be43c79a3809a499bc3d133de0"}, + "plug_cowboy": {:hex, :plug_cowboy, "2.8.1", "5aa391a5e8d1ac3192e36a3bcaff12b5fd6ef6c7e29b53a38e63a860783e77d0", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "4c200288673d5bc86a0ab7dc6a2a069176a74e5d573ef62740a1c517458a5f26"}, "plug_crypto": {:hex, :plug_crypto, "2.1.1", "19bda8184399cb24afa10be734f84a16ea0a2bc65054e23a62bb10f06bc89491", [:mix], [], "hexpm", "6470bce6ffe41c8bd497612ffde1a7e4af67f36a15eea5f921af71cf3e11247c"}, + "postgrex": {:hex, :postgrex, "0.22.2", "4aec14df2a72722aee92492566edbeeb44e233ecb86b1915d03136297ef1385d", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "8946382ddb06294f56026ac4278b3cc212bac8a2c82ed68b4087819ed1abc53b"}, + "ranch": {:hex, :ranch, "2.2.0", "25528f82bc8d7c6152c57666ca99ec716510fe0925cb188172f41ce93117b1b0", [:make, :rebar3], [], "hexpm", "fa0b99a1780c80218a4197a59ea8d3bdae32fbff7e88527d7d8a4787eff4f8e7"}, "telemetry": {:hex, :telemetry, "1.4.2", "a0cb522801dffb1c49fe6e30561badffc7b6d0e180db1300df759faa22062855", [:rebar3], [], "hexpm", "928f6495066506077862c0d1646609eed891a4326bee3126ba54b60af61febb1"}, "telemetry_metrics": {:hex, :telemetry_metrics, "1.1.0", "5bd5f3b5637e0abea0426b947e3ce5dd304f8b3bc6617039e2b5a008adc02f8f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e7b79e8ddfde70adb6db8a6623d1778ec66401f366e9a8f5dd0955c56bc8ce67"}, "telemetry_poller": {:hex, :telemetry_poller, "1.3.0", "d5c46420126b5ac2d72bc6580fb4f537d35e851cc0f8dbd571acf6d6e10f5ec7", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "51f18bed7128544a50f75897db9974436ea9bfba560420b646af27a9a9b35211"}, diff --git a/apps/csys/priv/static/docs b/apps/csys/priv/static/docs new file mode 120000 index 0000000..8e28a2b --- /dev/null +++ b/apps/csys/priv/static/docs @@ -0,0 +1 @@ +/home/helmutm/hugo/0-public/cco/ \ No newline at end of file diff --git a/apps/csys/priv/static/favicon.ico b/apps/csys/priv/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..7f372bfc21cdd8cb47585339d5fa4d9dd424402f GIT binary patch literal 152 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=@t!V@Ar*{oFEH`~d50E!_s``s q?{G*w(7?#d#v@^nKnY_HKaYb01EZMZjMqTJ89ZJ6T-G@yGywoKK_h|y literal 0 HcmV?d00001 diff --git a/apps/csys/priv/static/robots.txt b/apps/csys/priv/static/robots.txt new file mode 100644 index 0000000..26e06b5 --- /dev/null +++ b/apps/csys/priv/static/robots.txt @@ -0,0 +1,5 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/config/config.exs b/config/config.exs index 3dca519..1dab088 100644 --- a/config/config.exs +++ b/config/config.exs @@ -11,7 +11,7 @@ config :scopes, Scopes.Web.Server.Endpoint, url: [host: "localhost"], adapter: Bandit.PhoenixAdapter, render_errors: [ - formats: [json: ScopesApiWeb.ErrorJSON], + formats: [json: Scopes.Web.Server.ErrorJSON], layout: false ], #pubsub_server: Scopes.Web.Server.PubSub, diff --git a/lib/web/server/error_json.ex b/lib/web/server/error_json.ex new file mode 100644 index 0000000..bf05c9b --- /dev/null +++ b/lib/web/server/error_json.ex @@ -0,0 +1,28 @@ +defmodule Scopes.Web.Server.ErrorJSON do + @moduledoc """ + This module is invoked by your endpoint in case of errors on JSON requests. + + See config/config.exs. + """ + + alias Scopes.Util + require Logger + require Util + + # If you want to customize a particular status code, + # you may add your own clauses, such as: + # + # def render("500.json", _assigns) do + # %{errors: %{detail: "Internal Server Error"}} + # end + + # By default, Phoenix returns the status message from + # the template name. For example, "404.json" becomes + # "Not Found". + def render(template, assigns) do + message = assigns.reason.message + Logger.warning(Util.show [message]) + %{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}} + end +end + diff --git a/lib/web/server/router.ex b/lib/web/server/router.ex index 83b6660..9a78842 100644 --- a/lib/web/server/router.ex +++ b/lib/web/server/router.ex @@ -45,7 +45,7 @@ defmodule Scopes.Web.Server.JSON do require Util def index(resp) do - Logger.info(Util.show [resp]) + Logger.info(Util.show [resp.conn.assigns]) {_conn, message} = Map.pop(resp, :conn) message end diff --git a/mix.exs b/mix.exs index 4ae5531..6a347c2 100644 --- a/mix.exs +++ b/mix.exs @@ -17,7 +17,7 @@ defmodule Scopes.MixProject do # Run "mix help compile.app" to learn about applications. def application do [ - mod: {Scopes.Application, []}, + #mod: {Scopes.Application, []}, extra_applications: [:logger, :runtime_tools] ] end diff --git a/projects/demo/config/config.exs b/projects/demo/config/config.exs deleted file mode 100644 index bb906fb..0000000 --- a/projects/demo/config/config.exs +++ /dev/null @@ -1,10 +0,0 @@ -# scopes: basic config file - -import Config - -config :logger, :default_formatter, - format: "$date $time [$level] $metadata $message\n", - colors: [enabled: false], - metadata: [:mfa, :pid] - -import_config "#{config_env()}.exs" diff --git a/projects/demo/config/test.exs b/projects/demo/config/test.exs deleted file mode 100644 index 5185143..0000000 --- a/projects/demo/config/test.exs +++ /dev/null @@ -1,9 +0,0 @@ -# scopes: config file for testing - -import Config - -config :logger, :default_handler, - level: System.get_env("SCOPES_LOG_LEVEL", "info") |> String.to_atom, - config: [ - file: ~c"test/log/scopes_test.log" - ]