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
This commit is contained in:
parent
edcab37c7d
commit
8f762d47fa
8 changed files with 59 additions and 3 deletions
4
.formatter.exs
Normal file
4
.formatter.exs
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Used by "mix format"
|
||||
[
|
||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||
]
|
18
lib/privacy_revolver.ex
Normal file
18
lib/privacy_revolver.ex
Normal file
|
@ -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
|
15
lib/privacy_revolver/application.ex
Normal file
15
lib/privacy_revolver/application.ex
Normal file
|
@ -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
|
10
lib/privacy_revolver/router.ex
Normal file
10
lib/privacy_revolver/router.ex
Normal file
|
@ -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
|
4
mix.exs
4
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
|
||||
|
||||
|
|
2
mix.lock
2
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"},
|
||||
|
|
8
test/privacy_revolver_test.exs
Normal file
8
test/privacy_revolver_test.exs
Normal file
|
@ -0,0 +1,8 @@
|
|||
defmodule PrivacyRevolverTest do
|
||||
use ExUnit.Case
|
||||
doctest PrivacyRevolver
|
||||
|
||||
test "greets the world" do
|
||||
assert PrivacyRevolver.hello() == :world
|
||||
end
|
||||
end
|
1
test/test_helper.exs
Normal file
1
test/test_helper.exs
Normal file
|
@ -0,0 +1 @@
|
|||
ExUnit.start()
|
Loading…
Reference in a new issue