Skip to content

Instantly share code, notes, and snippets.

@siddhant3030
Created August 19, 2020 14:10
Show Gist options
  • Save siddhant3030/18f88d173bbf7f876f675682caae9360 to your computer and use it in GitHub Desktop.
Save siddhant3030/18f88d173bbf7f876f675682caae9360 to your computer and use it in GitHub Desktop.
defmodule TuringWeb.Router do
use TuringWeb, :router
use Plug.ErrorHandler
use Sentry.Plug
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
plug Phoenix.LiveView.Flash
end
pipeline :graphql do
plug(:accepts, ["json"])
plug(TuringWeb.Context)
end
pipeline :authorized do
plug :fetch_session
plug Guardian.Plug.Pipeline,
module: Turing.Auth.Guardian,
error_handler: Turing.Auth.ErrorHandler
plug Guardian.Plug.VerifySession
plug Guardian.Plug.LoadResource
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", TuringWeb do
pipe_through [:browser, :authorized]
get "/", PageController, :index
live "/chat/conversations/:conversation_id/users/:user_id", Live.Chat.Conversation, as: :chat
live "/leaderboard", Live.Leaderboard, as: :leaderboard
live "/profile/edit", Live.Accounts.User, as: :user
delete "/sign_in", SessionController, :sign_out
end
scope "/", TuringWeb do
pipe_through :browser
get "/sign_in", SessionController, :sign_in
get "/sign_up", UserController, :sign_up
end
if Mix.env() == :dev do
scope "/graphiql" do
forward("/", Absinthe.Plug.GraphiQL, schema: Turing.Graphql.Schema)
end
end
scope "/api" do
pipe_through(:graphql)
forward("/", Absinthe.Plug, schema: Turing.Graphql.Schema)
end
# Other scopes may use custom stacks.
# scope "/api", TuringWeb do
# pipe_through :api
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment