From 840cbe251c4f561cb952f5ef3313ec8d54c46ebf Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Tue, 20 Feb 2024 22:15:26 -0600 Subject: [PATCH] mix phx.server working --- main.ex | 35 ++++++++++++++++++----------------- readme.md | 2 +- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/main.ex b/main.ex index 349a8d9..786833a 100644 --- a/main.ex +++ b/main.ex @@ -1,19 +1,3 @@ -# config -counter = :counters.new(1, []) - -Application.put_env(:sfe, Sfe.Endpoint, - http: [ip: {127, 0, 0, 1}, port: 5001], - pubsub_server: Sfe.PubSub, - adapter: Bandit.PhoenixAdapter, - debug_errors: true, - code_reloader: true, - server: true, - live_view: [signing_salt: "aaaaaaaa"], - secret_key_base: String.duplicate("a", 64) -) - -Application.put_env(:sfe, Sfe.HomeLive, counter_ref: counter) - # application defmodule Sfe do defmodule Application do @@ -24,6 +8,23 @@ defmodule Sfe do def start(_type, _args) do Logger.debug("Sfe starting...") + # config + counter = :counters.new(1, []) + dbg(counter) + + Elixir.Application.put_env(:sfe, Sfe.Endpoint, + http: [ip: {127, 0, 0, 1}, port: 5001], + pubsub_server: Sfe.PubSub, + adapter: Bandit.PhoenixAdapter, + debug_errors: true, + code_reloader: true, + server: true, + live_view: [signing_salt: "aaaaaaaa"], + secret_key_base: String.duplicate("a", 64) + ) + + Elixir.Application.put_env(:sfe, Sfe.HomeLive, counter_ref: counter) + children = [ Sfe.Endpoint, {Phoenix.PubSub, name: Sfe.PubSub} @@ -116,7 +117,7 @@ defmodule Sfe.HomeLive do dbg(:counters.sub(counter_ref(), 1, 1)) counter_value(socket) end - + def handle_info(%{topic: "counter", event: "counter", payload: cval}, socket) do {:noreply, assign(socket, :count, cval)} end diff --git a/readme.md b/readme.md index 75384e0..b833cf3 100644 --- a/readme.md +++ b/readme.md @@ -17,7 +17,7 @@ and is used for nice things like code reloading by Phoenix, so not _quite_ as So here ya go! ```bash -elixir main.ex +mix phx.server ``` Or if you want "hot reloading"