starting to set up routing in csys app

This commit is contained in:
Helmut Merz 2026-06-15 16:39:55 +02:00
parent 8951df4282
commit b24c82fe57
6 changed files with 47 additions and 8 deletions

View file

@ -11,11 +11,13 @@ defmodule Scopes.CSys.Application do
def start(type, args) do def start(type, args) do
IO.puts("Hello CSys") IO.puts("Hello CSys")
Logger.info(Util.show [type, args]) Logger.info(Util.show [type, args])
# input_neurons = Environ.create_input
IO.inspect Scopes.CSys.Server.Endpoint.child_spec(input: %{[:csys, :s01] => "dummy"})
children = [ children = [
#Scopes.Web.Server.Endpoint #Scopes.CSys.Server.Endpoint
Scopes.CSys.Server.Endpoint {Scopes.CSys.Server.Endpoint, input: %{[:csys, :s01] => "dummy"}}
] ]
opts = [strategy: :one_for_one, name: Scopes.Supervisor] opts = [strategy: :one_for_one, name: Scopes.CSys.Supervisor]
Supervisor.start_link(children, opts) Supervisor.start_link(children, opts)
end end
end end

View file

@ -1,6 +1,12 @@
defmodule Scopes.CSys.Server.Endpoint do defmodule Scopes.CSys.Server.Endpoint do
use Phoenix.Endpoint, otp_app: :scopes_csys use Phoenix.Endpoint, otp_app: :scopes_csys
def init(arg) do
IO.inspect(arg)
IO.inspect(Process.get())
:ignore
end
plug Plug.Static, plug Plug.Static,
at: "/", at: "/",
from: :scopes_csys, from: :scopes_csys,
@ -15,5 +21,6 @@ defmodule Scopes.CSys.Server.Endpoint do
pass: ["*/*"], pass: ["*/*"],
json_decoder: Phoenix.json_library() json_decoder: Phoenix.json_library()
plug Scopes.Web.Server.Router plug Scopes.CSys.Server.Router
#input_neurons: @input
end end

View file

@ -0,0 +1,23 @@
defmodule Scopes.CSys.Server.Router do
use Scopes.Web.Server, :router
pipeline :api do
plug :accepts, ["json"]
end
scope "/api", Scopes.CSys.Server do
pipe_through :api
match :*, "/csys/:action/s01/:item", Controller, :index
end
end
defmodule Scopes.CSys.Server.Controller do
use Scopes.Web.Server, :controller
def index(conn, params) do
# input_neuron = Environ.get_input(:csys, :s01)
json(conn, params)
#render(conn, :index, message: "Hello CSys")
end
end

View file

@ -19,8 +19,8 @@ defmodule Scopes.Web.Server.ErrorJSON do
# By default, Phoenix returns the status message from # By default, Phoenix returns the status message from
# the template name. For example, "404.json" becomes # the template name. For example, "404.json" becomes
# "Not Found". # "Not Found".
def render(template, assigns) do def render(template, resp) do
message = assigns.reason.message message = resp.reason.message
Logger.warning(Util.show [message]) Logger.warning(Util.show [message])
%{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}} %{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}}
end end

View file

@ -17,8 +17,11 @@ defmodule Scopes.MixProject do
# Run "mix help compile.app" to learn about applications. # Run "mix help compile.app" to learn about applications.
def application do def application do
[ [
#mod: {Scopes.Application, []}, mod: {Scopes.Application, []},
extra_applications: [:logger, :runtime_tools] extra_applications: [:logger, :runtime_tools],
env: [
serve_endpoints: false
]
] ]
end end

View file

@ -4,8 +4,12 @@ defmodule Scopes.CoreActorTest do
describe "actors:" do describe "actors:" do
test "basic-life-cycle" do test "basic-life-cycle" do
Registry.start_link(keys: :unique, name: Actors)
this = self() this = self()
ac = Actor.create(fn msg -> send(this, msg) end) ac = Actor.create(fn msg -> send(this, msg) end)
# Actor.register(Actors, :demo, [])
# [{pid, _value}] = Registry.lookup(Actors, :demo)
# assert pid == ac
Actor.send(ac, "Hello Actor!") Actor.send(ac, "Hello Actor!")
assert_receive "Hello Actor!" assert_receive "Hello Actor!"
Actor.become(ac, fn _msg -> send(this, "Goodbye") end) Actor.become(ac, fn _msg -> send(this, "Goodbye") end)