{"action":"created","issue":{"url":"https://api.github.com/repos/twisted/klein/issues/41","labels_url":"https://api.github.com/repos/twisted/klein/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/twisted/klein/issues/41/comments","events_url":"https://api.github.com/repos/twisted/klein/issues/41/events","html_url":"https://github.com/twisted/klein/issues/41","id":25463916,"number":41,"title":"Unable to serve index.html at the route \"/\"","user":{"login":"michaelnt","id":265155,"avatar_url":"https://avatars.githubusercontent.com/u/265155?v=3","gravatar_id":"","url":"https://api.github.com/users/michaelnt","html_url":"https://github.com/michaelnt","followers_url":"https://api.github.com/users/michaelnt/followers","following_url":"https://api.github.com/users/michaelnt/following{/other_user}","gists_url":"https://api.github.com/users/michaelnt/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelnt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelnt/subscriptions","organizations_url":"https://api.github.com/users/michaelnt/orgs","repos_url":"https://api.github.com/users/michaelnt/repos","events_url":"https://api.github.com/users/michaelnt/events{/privacy}","received_events_url":"https://api.github.com/users/michaelnt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-01-12T15:14:44Z","updated_at":"2015-05-04T23:37:50Z","closed_at":null,"body":"The following doesn't work, returning a file not found error.\r\n\r\n```python\r\n@app.route(\"/\")\r\ndef root(request):\r\n   return File(\"index.html\")\r\n```\r\n\r\nThe following works\r\n\r\n```python\r\n@app.route(\"/index.html\")\r\ndef root(request):\r\n   return File(\"index.html\")\r\n```\r\nAnd this also works\r\n\r\n```python\r\n@app.route(\"/\")\r\ndef root(request):\r\n   return \"Hello\"\r\n```\r\n\r\nThis is a failing test that I think illustrates the problem\r\n\r\n```python\r\n    def test_staticRoot_noBranch(self):\r\n        \"\"\"\r\n        The following should return the contents of the file index.html\r\n\r\n        @app.route(\"/\")\r\n        def root(request):\r\n            return File(\"index.html\")\r\n        \r\n        \"\"\"\r\n        app = self.app\r\n        request = requestMock(\"/\")\r\n\r\n        @app.route(\"/\")\r\n        def root(request):\r\n            return File(__file__)\r\n\r\n        d = _render(self.kr, request)\r\n\r\n        def _cb(result):\r\n            self.assertEqual(request.getWrittenData(), \r\n                open(__file__).read())\r\n            self.assertEqual(request.finishCount, 1)\r\n\r\n        d.addCallback(_cb)\r\n        return d\r\n```"},"comment":{"url":"https://api.github.com/repos/twisted/klein/issues/comments/98885039","html_url":"https://github.com/twisted/klein/issues/41#issuecomment-98885039","issue_url":"https://api.github.com/repos/twisted/klein/issues/41","id":98885039,"user":{"login":"posita","id":222581,"avatar_url":"https://avatars.githubusercontent.com/u/222581?v=3","gravatar_id":"","url":"https://api.github.com/users/posita","html_url":"https://github.com/posita","followers_url":"https://api.github.com/users/posita/followers","following_url":"https://api.github.com/users/posita/following{/other_user}","gists_url":"https://api.github.com/users/posita/gists{/gist_id}","starred_url":"https://api.github.com/users/posita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/posita/subscriptions","organizations_url":"https://api.github.com/users/posita/orgs","repos_url":"https://api.github.com/users/posita/repos","events_url":"https://api.github.com/users/posita/events{/privacy}","received_events_url":"https://api.github.com/users/posita/received_events","type":"User","site_admin":false},"created_at":"2015-05-04T23:37:50Z","updated_at":"2015-05-04T23:37:50Z","body":"*UPDATE: The technique from #59 seems to work for me. I have no idea how to override the MIME type for a static file though, so (depending on your system), your browser might download this as `text/x-python` instead of `text/plain`. :confused:*\r\n\r\n```py\r\nfrom klein import Klein\r\nfrom twisted.web.static import File\r\n\r\napp = Klein()\r\n\r\n@app.route('/', branch=True)\r\ndef root(request):\r\n    f = File(__file__)\r\n    f.isLeaf = True\r\n    return f\r\n\r\nif __name__ == '__main__':\r\n   app.run('localhost', 8080)\r\n```"}}