defmodule Griffin.Web.Plug do @moduledoc """ Griffin Cowboy Plug to serve files from the output directory """ import Plug.Conn @output_path Application.compile_env(:griffin, :output_path, "_site") def init(options) do options end @doc """ Simple route that serves files from the configured Griffin output directory. """ @spec call(Plug.Conn.t(), any) :: Plug.Conn.t() def call(conn, _opts) do filename = "#{@output_path}/#{conn.request_path}" if File.exists?(filename) do send_file(conn, 200, filename) else send_resp(conn, 404, "File not found") end end end