diff --git a/config/runtime.exs b/config/runtime.exs new file mode 100644 index 0000000..2dfa712 --- /dev/null +++ b/config/runtime.exs @@ -0,0 +1,3 @@ +import Config + +config(:queen, :secret_key_base, System.fetch_env!("QUEEN_COOKIE_SECRET")) diff --git a/lib/queen.ex b/lib/queen.ex index b626ce3..650d695 100644 --- a/lib/queen.ex +++ b/lib/queen.ex @@ -1,12 +1,27 @@ -defmodule Queen do - import Plug.Conn +defmodule QueenRouter do + use Plug.Router - def init(opts) do - opts + plug(Plug.Logger) + plug(:match) + plug(:dispatch) + + plug(Plug.Session, store: :cookie, key: "_queen_session", signing_salt: "J6PHP10BHF23") + plug(:fetch_session) + plug(Plug.CSRFProtection) + + get "/signup" do + fetch_session(conn) |> put_session(:verify, "meow") |> send_resp(200, "signup") end - def call(conn, _opts) do - :logger.debug("saying hello") - send_resp(conn, 200, "hello from queen") + get "/success/:payment" do + conn = fetch_session(conn) + verify = get_session(conn, :verify) + :logger.info("got verify: #{verify}") + :logger.info("got payment receipt code #{payment}") + send_resp(conn, 200, "huzzah") + end + + match _ do + send_resp(conn, 404, "you lost, kitty-cat?") end end diff --git a/lib/queen/application.ex b/lib/queen/application.ex index 5a9a22b..e2ed925 100644 --- a/lib/queen/application.ex +++ b/lib/queen/application.ex @@ -8,7 +8,7 @@ defmodule Queen.Application do @impl true def start(_type, _args) do children = [ - {Bandit, plug: Queen} + {Bandit, plug: QueenRouter} # Starts a worker by calling: Queen.Worker.start_link(arg) # {Queen.Worker, arg} ] diff --git a/mix.exs b/mix.exs index e9f401f..3461570 100644 --- a/mix.exs +++ b/mix.exs @@ -15,7 +15,8 @@ defmodule Queen.MixProject do def application do [ # extra_applications: [:logger, :ecto_sqlite3, :ecto, :bandit, :plug] - extra_applications: [:logger] + extra_applications: [:logger], + mod: {Queen.Application, []} ] end