From 8f762d47fa002c5cc19153db4ae62cb0d438a6ad Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Fri, 22 Oct 2021 18:28:12 -0600 Subject: Setup basic Plug.Router framework for serving requests Rather than use a full blown framework*, adding basic routing with Plug.Router seems to make more sense, since I'm not planning on hosting any content through this app. The app itself will just be endpoints for all available services that redirect the user to an available instance for the requested service. Note that I might change my mind about this, but that's unlikely. At most there would just be a home page with info about available instances, but even then that seems kinda pointless. Trying to keep this as absolutely simple as possible. *like Phoenix --- lib/privacy_revolver.ex | 18 ++++++++++++++++++ lib/privacy_revolver/application.ex | 15 +++++++++++++++ lib/privacy_revolver/router.ex | 10 ++++++++++ 3 files changed, 43 insertions(+) create mode 100644 lib/privacy_revolver.ex create mode 100644 lib/privacy_revolver/application.ex create mode 100644 lib/privacy_revolver/router.ex (limited to 'lib') diff --git a/lib/privacy_revolver.ex b/lib/privacy_revolver.ex new file mode 100644 index 0000000..5de8e06 --- /dev/null +++ b/lib/privacy_revolver.ex @@ -0,0 +1,18 @@ +defmodule PrivacyRevolver do + @moduledoc """ + Documentation for `PrivacyRevolver`. + """ + + @doc """ + Hello world. + + ## Examples + + iex> PrivacyRevolver.hello() + :world + + """ + def hello do + :world + end +end diff --git a/lib/privacy_revolver/application.ex b/lib/privacy_revolver/application.ex new file mode 100644 index 0000000..de38e6e --- /dev/null +++ b/lib/privacy_revolver/application.ex @@ -0,0 +1,15 @@ +defmodule PrivacyRevolver.Application do + @moduledoc false + + use Application + + @impl true + def start(_type, _args) do + children = [ + Plug.Cowboy.child_spec(scheme: :http, plug: PrivacyRevolver.Router, options: [port: 4001]) + ] + + opts = [strategy: :one_for_one, name: PrivacyRevolver.Supervisor] + Supervisor.start_link(children, opts) + end +end diff --git a/lib/privacy_revolver/router.ex b/lib/privacy_revolver/router.ex new file mode 100644 index 0000000..cf702fe --- /dev/null +++ b/lib/privacy_revolver/router.ex @@ -0,0 +1,10 @@ +defmodule PrivacyRevolver.Router do + use Plug.Router + + plug :match + plug :dispatch + + get "/ping" do + send_resp(conn, 200, "pong") + end +end -- cgit v1.2.3