Created
November 28, 2016 02:04
-
-
Save davejlong/d2d39d83558681a14777d710b38e4bc7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Uebersample.Router do | |
use Plug.Router | |
plug Ueberauth | |
alias Ueberauth.Strategy.Helpers | |
plug :match | |
plug :dispatch | |
get "/hello" do | |
conn |> send_resp(200, "Hello, World!") | |
end | |
get "/auth/:provider/callback" do | |
conn |> redirect("/hello") | |
end | |
match _ do | |
conn |> send_resp(404, "Oops! Page not found.") | |
end | |
defp redirect(conn, url) do | |
body = "<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>" | |
conn | |
|> put_resp_header("location", url) | |
|> put_resp_header("content-type", "text/html") | |
|> send_resp(conn.status || 302, body) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment