From 516a1eac2468b4278374f66f912ef94e0474ec79 Mon Sep 17 00:00:00 2001 From: Radek Stepan Date: Tue, 22 May 2012 17:35:53 +0100 Subject: [PATCH] refactor out https to github --- app.coffee | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app.coffee b/app.coffee index fff0dec..bcd587e 100644 --- a/app.coffee +++ b/app.coffee @@ -8,6 +8,15 @@ options = path: "/repos/intermine/InterMine/issues" method: "GET" +getIssues = (callback) -> + https.request(options, (response) -> + if response.statusCode is 200 + json = "" + response.on "data", (chunk) -> json += chunk + + response.on "end", -> callback JSON.parse json + ).end() + app = express.createServer() app.configure -> @@ -34,16 +43,10 @@ app.configure 'production', -> # Routes app.get '/issues', (req, res) -> - https.request(options, (response) -> - if response.statusCode is 200 - json = "" - response.on "data", (chunk) -> json += chunk - - response.on "end", -> - res.render 'issues', - 'issues': JSON.parse json - , (html) -> res.send html, 'Content-Type': 'text/html', 200 - ).end() + getIssues (issues) -> + res.render 'issues', + 'issues': issues + , (html) -> res.send html, 'Content-Type': 'text/html', 200 app.listen 3000 console.log "Express server listening to port 3000" \ No newline at end of file