-
-
Save j-mcnally/3353084f21cebf23c372 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 Exq.RouterPlug do | |
require Logger | |
alias Exq.RouterPlug.Router | |
def init(options), do: options | |
def call(conn, opts) do | |
namespace(conn, opts, opts[:namespace] || "exq") | |
end | |
def namespace(%Plug.Conn{path_info: [ns | path]} = conn, opts, ns) do | |
conn = Plug.Conn.assign(conn, :namespace, opts[:namespace]) | |
Router.call(%Plug.Conn{conn | path_info: path}, Router.init(opts)) | |
end | |
def namespace(conn, _opts, _ns), do: conn | |
defmodule Router do | |
import Plug.Conn | |
use Plug.Router | |
plug Plug.Static, at: "/", from: :exq | |
plug :match | |
plug :dispatch | |
get "/api/queues" do | |
Logger.debug "YOLO" | |
conn |> halt | |
end | |
match _ do | |
path = Path.join([Application.app_dir(:exq), "priv/static", "index.html"]) | |
myhtml = EEx.eval_file(path, [namespace: "#{conn.assigns[:namespace]}/"]) | |
conn |> | |
put_resp_header("content-type", "text/html") |> | |
send_resp(200, myhtml) |> | |
halt | |
end | |
end | |
end |
chrismccord
commented
Oct 25, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment