summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Busby <noreply+git@benbusby.com>2021-10-22 18:28:12 -0600
committerBen Busby <noreply+git@benbusby.com>2021-10-22 18:28:12 -0600
commit8f762d47fa002c5cc19153db4ae62cb0d438a6ad (patch)
treee3c374dca633a1a5754aeef2c04798b1437d75a2
parentedcab37c7d48259c7cf7969f95cb4efdbd728c93 (diff)
downloadfarside-8f762d47fa002c5cc19153db4ae62cb0d438a6ad.tar.gz
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
-rw-r--r--.formatter.exs4
-rw-r--r--lib/privacy_revolver.ex18
-rw-r--r--lib/privacy_revolver/application.ex15
-rw-r--r--lib/privacy_revolver/router.ex10
-rw-r--r--mix.exs4
-rw-r--r--mix.lock2
-rw-r--r--test/privacy_revolver_test.exs8
-rw-r--r--test/test_helper.exs1
8 files changed, 59 insertions, 3 deletions
diff --git a/.formatter.exs b/.formatter.exs
new file mode 100644
index 0000000..d2cda26
--- /dev/null
+++ b/.formatter.exs
@@ -0,0 +1,4 @@
+# Used by "mix format"
+[
+ inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
+]
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
diff --git a/mix.exs b/mix.exs
index 3a85d2d..7c1c723 100644
--- a/mix.exs
+++ b/mix.exs
@@ -3,7 +3,7 @@ defmodule RouterExample.MixProject do
def project do
[
- app: :router_example,
+ app: :privacy_revolver,
version: "0.1.0",
elixir: "~> 1.8",
start_permanent: Mix.env() == :prod,
@@ -15,7 +15,7 @@ defmodule RouterExample.MixProject do
def application do
[
extra_applications: [:logger],
- mod: {RouterExample.Application, []}
+ mod: {PrivacyRevolver.Application, []}
]
end
diff --git a/mix.lock b/mix.lock
index b5071fd..1ada2e4 100644
--- a/mix.lock
+++ b/mix.lock
@@ -8,7 +8,7 @@
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
- "mime": {:hex, :mime, "2.0.1", "0de4c81303fe07806ebc2494d5321ce8fb4df106e34dd5f9d787b637ebadc256", [:mix], [], "hexpm", "7a86b920d2aedce5fb6280ac8261ac1a739ae6c1a1ad38f5eadf910063008942"},
+ "mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"plug": {:hex, :plug, "1.12.1", "645678c800601d8d9f27ad1aebba1fdb9ce5b2623ddb961a074da0b96c35187d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d57e799a777bc20494b784966dc5fbda91eb4a09f571f76545b72a634ce0d30b"},
diff --git a/test/privacy_revolver_test.exs b/test/privacy_revolver_test.exs
new file mode 100644
index 0000000..aa8fa79
--- /dev/null
+++ b/test/privacy_revolver_test.exs
@@ -0,0 +1,8 @@
+defmodule PrivacyRevolverTest do
+ use ExUnit.Case
+ doctest PrivacyRevolver
+
+ test "greets the world" do
+ assert PrivacyRevolver.hello() == :world
+ end
+end
diff --git a/test/test_helper.exs b/test/test_helper.exs
new file mode 100644
index 0000000..869559e
--- /dev/null
+++ b/test/test_helper.exs
@@ -0,0 +1 @@
+ExUnit.start()