{"action":"created","comment":{"url":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/comments/66452963","id":66452963,"diff_hunk":"@@ -267,17 +268,77 @@ fn build(config: &Config) {\n     };\n }\n \n+fn static_file_handler(dest: &str, req: Request, res: Response) {\n+    let path = PathBuf::from(format!(\"{}{}\", dest, req.uri));\n+\n+    let serve_path = if path.is_file() {\n+        // try to point the serve path to `path` if it corresponds to a file\n+        path.clone()\n+    } else {\n+        // try to point the serve path into a \"index.html\" file in the requested\n+        // path\n+        path.join(\"index.html\")\n+    };\n+\n+    // if the request points to a file and it exists, read and serve it\n+    if serve_path.exists() {\n+        let mut file = match File::open(serve_path) {\n+            Ok(f) => f,\n+            Err(e) => {\n+                error!(\"{}\", e);\n+                std::process::exit(1);\n+            }\n+        };\n+\n+        let mut buffer: Vec<u8> = vec![];\n+\n+        match file.read_to_end(&mut buffer) {\n+            Err(e) => {\n+                error!(\"{}\", e);\n+                std::process::exit(1);\n+            },\n+            Ok(_) => {},\n+        };\n+\n+        match res.send(&buffer) {\n+            Err(e) => {\n+                error!(\"{}\", e);\n+                std::process::exit(1);\n+            },\n+            Ok(()) => {},\n+        };\n+    }\n+}\n+\n fn serve(dest: &str, port: &str) {\n     info!(\"Serving {:?} through static file server\", dest);\n-    let mut server = Nickel::new();\n-    server.options = NickelOptions::default().output_on_listen(false);\n-\n-    server.utilize(StaticFilesHandler::new(dest));\n \n-    let ip = \"127.0.0.1:\".to_owned() + port;\n+    let ip = format!(\"127.0.0.1:{}\", port);\n     info!(\"Server Listening on {}\", &ip);\n     info!(\"Ctrl-c to stop the server\");\n-    server.listen(&*ip);\n+\n+    // attempts to create a server\n+    let http_server = match Server::http(&*ip) {\n+        Ok(server) => server,\n+        Err(e) => {\n+            error!(\"{}\", e);\n+            std::process::exit(1);\n+        }\n+    };\n+\n+    // need a clone because of closure's lifetime\n+    let dest_clone = dest.to_owned();","path":"src/main.rs","position":97,"original_position":97,"commit_id":"9edc73677c856f23594f397fc1c37208c70f6f10","original_commit_id":"9edc73677c856f23594f397fc1c37208c70f6f10","user":{"login":"LucioFranco","id":5758045,"avatar_url":"https://avatars.githubusercontent.com/u/5758045?v=3","gravatar_id":"","url":"https://api.github.com/users/LucioFranco","html_url":"https://github.com/LucioFranco","followers_url":"https://api.github.com/users/LucioFranco/followers","following_url":"https://api.github.com/users/LucioFranco/following{/other_user}","gists_url":"https://api.github.com/users/LucioFranco/gists{/gist_id}","starred_url":"https://api.github.com/users/LucioFranco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LucioFranco/subscriptions","organizations_url":"https://api.github.com/users/LucioFranco/orgs","repos_url":"https://api.github.com/users/LucioFranco/repos","events_url":"https://api.github.com/users/LucioFranco/events{/privacy}","received_events_url":"https://api.github.com/users/LucioFranco/received_events","type":"User","site_admin":false},"body":"You are right.","created_at":"2016-06-09T14:37:16Z","updated_at":"2016-06-09T14:37:16Z","html_url":"https://github.com/cobalt-org/cobalt.rs/pull/113#discussion_r66452963","pull_request_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/113","_links":{"self":{"href":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/comments/66452963"},"html":{"href":"https://github.com/cobalt-org/cobalt.rs/pull/113#discussion_r66452963"},"pull_request":{"href":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/113"}}},"pull_request":{"url":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/113","id":72963808,"html_url":"https://github.com/cobalt-org/cobalt.rs/pull/113","diff_url":"https://github.com/cobalt-org/cobalt.rs/pull/113.diff","patch_url":"https://github.com/cobalt-org/cobalt.rs/pull/113.patch","issue_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/issues/113","number":113,"state":"open","locked":false,"title":"Move from Nickel to Hyper","user":{"login":"DonRyuDragoni","id":4451827,"avatar_url":"https://avatars.githubusercontent.com/u/4451827?v=3","gravatar_id":"","url":"https://api.github.com/users/DonRyuDragoni","html_url":"https://github.com/DonRyuDragoni","followers_url":"https://api.github.com/users/DonRyuDragoni/followers","following_url":"https://api.github.com/users/DonRyuDragoni/following{/other_user}","gists_url":"https://api.github.com/users/DonRyuDragoni/gists{/gist_id}","starred_url":"https://api.github.com/users/DonRyuDragoni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DonRyuDragoni/subscriptions","organizations_url":"https://api.github.com/users/DonRyuDragoni/orgs","repos_url":"https://api.github.com/users/DonRyuDragoni/repos","events_url":"https://api.github.com/users/DonRyuDragoni/events{/privacy}","received_events_url":"https://api.github.com/users/DonRyuDragoni/received_events","type":"User","site_admin":false},"body":"As proposed in #109, I moved all Nickel-related code to Hyper. I wasn't sure of the best (or this project's) way of handling each error, so I unwrapped everything.\r\n\r\nI also couldn't find something similar to `StaticFilesHandler` in hyper, so I wrote a very basic handler that could be improved upon.","created_at":"2016-06-07T23:12:57Z","updated_at":"2016-06-09T14:37:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"89b9afcde1a771cad207b2e3a13462067723e57e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/113/commits","review_comments_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/113/comments","review_comment_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/issues/113/comments","statuses_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/statuses/9edc73677c856f23594f397fc1c37208c70f6f10","head":{"label":"DonRyuDragoni:nickel-to-hyper","ref":"nickel-to-hyper","sha":"9edc73677c856f23594f397fc1c37208c70f6f10","user":{"login":"DonRyuDragoni","id":4451827,"avatar_url":"https://avatars.githubusercontent.com/u/4451827?v=3","gravatar_id":"","url":"https://api.github.com/users/DonRyuDragoni","html_url":"https://github.com/DonRyuDragoni","followers_url":"https://api.github.com/users/DonRyuDragoni/followers","following_url":"https://api.github.com/users/DonRyuDragoni/following{/other_user}","gists_url":"https://api.github.com/users/DonRyuDragoni/gists{/gist_id}","starred_url":"https://api.github.com/users/DonRyuDragoni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DonRyuDragoni/subscriptions","organizations_url":"https://api.github.com/users/DonRyuDragoni/orgs","repos_url":"https://api.github.com/users/DonRyuDragoni/repos","events_url":"https://api.github.com/users/DonRyuDragoni/events{/privacy}","received_events_url":"https://api.github.com/users/DonRyuDragoni/received_events","type":"User","site_admin":false},"repo":{"id":60630941,"name":"cobalt.rs","full_name":"DonRyuDragoni/cobalt.rs","owner":{"login":"DonRyuDragoni","id":4451827,"avatar_url":"https://avatars.githubusercontent.com/u/4451827?v=3","gravatar_id":"","url":"https://api.github.com/users/DonRyuDragoni","html_url":"https://github.com/DonRyuDragoni","followers_url":"https://api.github.com/users/DonRyuDragoni/followers","following_url":"https://api.github.com/users/DonRyuDragoni/following{/other_user}","gists_url":"https://api.github.com/users/DonRyuDragoni/gists{/gist_id}","starred_url":"https://api.github.com/users/DonRyuDragoni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DonRyuDragoni/subscriptions","organizations_url":"https://api.github.com/users/DonRyuDragoni/orgs","repos_url":"https://api.github.com/users/DonRyuDragoni/repos","events_url":"https://api.github.com/users/DonRyuDragoni/events{/privacy}","received_events_url":"https://api.github.com/users/DonRyuDragoni/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/DonRyuDragoni/cobalt.rs","description":"Static site generator written in Rust","fork":true,"url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs","forks_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/forks","keys_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/teams","hooks_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/hooks","issue_events_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/issues/events{/number}","events_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/events","assignees_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/assignees{/user}","branches_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/branches{/branch}","tags_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/tags","blobs_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/git/refs{/sha}","trees_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/statuses/{sha}","languages_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/languages","stargazers_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/stargazers","contributors_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/contributors","subscribers_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/subscribers","subscription_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/subscription","commits_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/commits{/sha}","git_commits_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/git/commits{/sha}","comments_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/comments{/number}","issue_comment_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/issues/comments{/number}","contents_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/contents/{+path}","compare_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/merges","archive_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/downloads","issues_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/issues{/number}","pulls_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/pulls{/number}","milestones_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/milestones{/number}","notifications_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/labels{/name}","releases_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/releases{/id}","deployments_url":"https://api.github.com/repos/DonRyuDragoni/cobalt.rs/deployments","created_at":"2016-06-07T16:58:05Z","updated_at":"2016-06-07T16:58:05Z","pushed_at":"2016-06-08T19:07:05Z","git_url":"git://github.com/DonRyuDragoni/cobalt.rs.git","ssh_url":"git@github.com:DonRyuDragoni/cobalt.rs.git","clone_url":"https://github.com/DonRyuDragoni/cobalt.rs.git","svn_url":"https://github.com/DonRyuDragoni/cobalt.rs","homepage":"","size":200,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cobalt-org:master","ref":"master","sha":"f0679c8a2f282ad88ea8e9757334d67863171840","user":{"login":"cobalt-org","id":9417410,"avatar_url":"https://avatars.githubusercontent.com/u/9417410?v=3","gravatar_id":"","url":"https://api.github.com/users/cobalt-org","html_url":"https://github.com/cobalt-org","followers_url":"https://api.github.com/users/cobalt-org/followers","following_url":"https://api.github.com/users/cobalt-org/following{/other_user}","gists_url":"https://api.github.com/users/cobalt-org/gists{/gist_id}","starred_url":"https://api.github.com/users/cobalt-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cobalt-org/subscriptions","organizations_url":"https://api.github.com/users/cobalt-org/orgs","repos_url":"https://api.github.com/users/cobalt-org/repos","events_url":"https://api.github.com/users/cobalt-org/events{/privacy}","received_events_url":"https://api.github.com/users/cobalt-org/received_events","type":"Organization","site_admin":false},"repo":{"id":25877885,"name":"cobalt.rs","full_name":"cobalt-org/cobalt.rs","owner":{"login":"cobalt-org","id":9417410,"avatar_url":"https://avatars.githubusercontent.com/u/9417410?v=3","gravatar_id":"","url":"https://api.github.com/users/cobalt-org","html_url":"https://github.com/cobalt-org","followers_url":"https://api.github.com/users/cobalt-org/followers","following_url":"https://api.github.com/users/cobalt-org/following{/other_user}","gists_url":"https://api.github.com/users/cobalt-org/gists{/gist_id}","starred_url":"https://api.github.com/users/cobalt-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cobalt-org/subscriptions","organizations_url":"https://api.github.com/users/cobalt-org/orgs","repos_url":"https://api.github.com/users/cobalt-org/repos","events_url":"https://api.github.com/users/cobalt-org/events{/privacy}","received_events_url":"https://api.github.com/users/cobalt-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cobalt-org/cobalt.rs","description":"Static site generator written in Rust","fork":false,"url":"https://api.github.com/repos/cobalt-org/cobalt.rs","forks_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/forks","keys_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/teams","hooks_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/hooks","issue_events_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/issues/events{/number}","events_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/events","assignees_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/assignees{/user}","branches_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/branches{/branch}","tags_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/tags","blobs_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/git/refs{/sha}","trees_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/statuses/{sha}","languages_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/languages","stargazers_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/stargazers","contributors_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/contributors","subscribers_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/subscribers","subscription_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/subscription","commits_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/commits{/sha}","git_commits_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/git/commits{/sha}","comments_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/comments{/number}","issue_comment_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/issues/comments{/number}","contents_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/contents/{+path}","compare_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/merges","archive_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/downloads","issues_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/issues{/number}","pulls_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls{/number}","milestones_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/milestones{/number}","notifications_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/labels{/name}","releases_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/releases{/id}","deployments_url":"https://api.github.com/repos/cobalt-org/cobalt.rs/deployments","created_at":"2014-10-28T16:04:40Z","updated_at":"2016-06-07T23:30:21Z","pushed_at":"2016-06-08T19:07:05Z","git_url":"git://github.com/cobalt-org/cobalt.rs.git","ssh_url":"git@github.com:cobalt-org/cobalt.rs.git","clone_url":"https://github.com/cobalt-org/cobalt.rs.git","svn_url":"https://github.com/cobalt-org/cobalt.rs","homepage":"","size":220,"stargazers_count":117,"watchers_count":117,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":25,"forks":24,"open_issues":25,"watchers":117,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/113"},"html":{"href":"https://github.com/cobalt-org/cobalt.rs/pull/113"},"issue":{"href":"https://api.github.com/repos/cobalt-org/cobalt.rs/issues/113"},"comments":{"href":"https://api.github.com/repos/cobalt-org/cobalt.rs/issues/113/comments"},"review_comments":{"href":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/113/comments"},"review_comment":{"href":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cobalt-org/cobalt.rs/pulls/113/commits"},"statuses":{"href":"https://api.github.com/repos/cobalt-org/cobalt.rs/statuses/9edc73677c856f23594f397fc1c37208c70f6f10"}}}}
{"actor":{"display_login":"LucioFranco"}}