mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
34 lines
763 B
Elixir
34 lines
763 B
Elixir
defmodule ChesstrainerWeb.RobotsController do
|
|
@moduledoc """
|
|
Serves `/robots.txt` with a sitemap URL that follows the deployment's host.
|
|
|
|
Built at runtime from the endpoint configuration rather than checked in as a
|
|
static file, so the sitemap stays correct across environments.
|
|
"""
|
|
|
|
use ChesstrainerWeb, :controller
|
|
|
|
def index(conn, _params) do
|
|
body =
|
|
if prelaunch?() do
|
|
"""
|
|
User-agent: *
|
|
Disallow: /
|
|
"""
|
|
else
|
|
"""
|
|
User-agent: *
|
|
Allow: /
|
|
|
|
Sitemap: #{url(conn, ~p"/sitemap.xml")}
|
|
"""
|
|
end
|
|
|
|
conn
|
|
|> put_resp_content_type("text/plain")
|
|
|> send_resp(200, body)
|
|
end
|
|
|
|
defp prelaunch?, do: Application.get_env(:chesstrainer, :prelaunch, false)
|
|
end
|