{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-lang/plug/issues/297","labels_url":"https://api.github.com/repos/elixir-lang/plug/issues/297/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/plug/issues/297/comments","events_url":"https://api.github.com/repos/elixir-lang/plug/issues/297/events","html_url":"https://github.com/elixir-lang/plug/pull/297","id":105789063,"number":297,"title":"Add index option to Plug.Static.","user":{"login":"tuvistavie","id":1436271,"avatar_url":"https://avatars.githubusercontent.com/u/1436271?v=3","gravatar_id":"","url":"https://api.github.com/users/tuvistavie","html_url":"https://github.com/tuvistavie","followers_url":"https://api.github.com/users/tuvistavie/followers","following_url":"https://api.github.com/users/tuvistavie/following{/other_user}","gists_url":"https://api.github.com/users/tuvistavie/gists{/gist_id}","starred_url":"https://api.github.com/users/tuvistavie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tuvistavie/subscriptions","organizations_url":"https://api.github.com/users/tuvistavie/orgs","repos_url":"https://api.github.com/users/tuvistavie/repos","events_url":"https://api.github.com/users/tuvistavie/events{/privacy}","received_events_url":"https://api.github.com/users/tuvistavie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-10T11:39:52Z","updated_at":"2015-09-10T13:10:40Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/elixir-lang/plug/pulls/297","html_url":"https://github.com/elixir-lang/plug/pull/297","diff_url":"https://github.com/elixir-lang/plug/pull/297.diff","patch_url":"https://github.com/elixir-lang/plug/pull/297.patch"},"body":"When trying to serve a static website using `Plug.Static`, I could not find\r\na way to get `index.html` to be served, so I tried to add this as an option.\r\nThis should not change the default behavior.\r\n\r\nI think it could be a little improved as a single call to `:prim_file.read_file_info`\r\nshould be enough for a single request (instead of first using `File.dir?`) first\r\nas I am here, but it would have needed some more refactoring so I preferred to\r\nkeep the PR simple."},"comment":{"url":"https://api.github.com/repos/elixir-lang/plug/issues/comments/139230089","html_url":"https://github.com/elixir-lang/plug/pull/297#issuecomment-139230089","issue_url":"https://api.github.com/repos/elixir-lang/plug/issues/297","id":139230089,"user":{"login":"ericmj","id":316890,"avatar_url":"https://avatars.githubusercontent.com/u/316890?v=3","gravatar_id":"","url":"https://api.github.com/users/ericmj","html_url":"https://github.com/ericmj","followers_url":"https://api.github.com/users/ericmj/followers","following_url":"https://api.github.com/users/ericmj/following{/other_user}","gists_url":"https://api.github.com/users/ericmj/gists{/gist_id}","starred_url":"https://api.github.com/users/ericmj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericmj/subscriptions","organizations_url":"https://api.github.com/users/ericmj/orgs","repos_url":"https://api.github.com/users/ericmj/repos","events_url":"https://api.github.com/users/ericmj/events{/privacy}","received_events_url":"https://api.github.com/users/ericmj/received_events","type":"User","site_admin":false},"created_at":"2015-09-10T13:10:40Z","updated_at":"2015-09-10T13:10:40Z","body":"I think a better approach is to add a function to `Plug.Static` to serve files from any plug. Taking your example it would look something like this:\r\n\r\n```elixir\r\ndefmodule StaticIndexPlug do\r\n   use Plug.Builder\r\n   use Plug.Router\r\n\r\n   plug Plug.Static,\r\n     at: \"/public\",\r\n     from: Path.expand(\"..\", __DIR__)\r\n\r\n  plug :match\r\n  plug :dispatch\r\n\r\n  get \"/\" do\r\n    Plug.Static.serve_file(conn, \"static.txt\")\r\n  end\r\n\r\n  match _ do\r\n    send_resp(conn, 404, \"Passthrough\")\r\n  end\r\nend\r\n```"}}