I am trying to get the identifier of a website based on its domain, but after writing a plug for it, i am running into a problem wherein all the links in the system are returning the root url content.
lib/myapp/plugs/request_var.ex
defmodule Myapp.Plug.RequestVar do
import Plug.Conn
@doc false
def init(default), do: default
@doc false
def call(conn, router) do
host = conn.host
if host == "ll.com" || host == "domain1.com" do
slug = "domain1"
else
slug = "domain2"
end
conn |> put_private(:site_slug, slug)
end
end
In lib/myapp/endpoint.ex
plug Myapp.Plug.RequestVar, Myapp.Router
plug Myapp.Router
Is anything wrong with this plug?
Edit: Fixed the "if" condition based on the responses.