proxy requests taking too long; closes #37
This commit is contained in:
parent
9d793a3265
commit
f02bf813e9
|
@ -20514,7 +20514,7 @@ if (typeof exports == "object") {
|
||||||
timeout = setTimeout(function() {
|
timeout = setTimeout(function() {
|
||||||
exited = true;
|
exited = true;
|
||||||
return cb('Request has timed out');
|
return cb('Request has timed out');
|
||||||
}, 3e3);
|
}, 1e4);
|
||||||
return req.end(function(err, data) {
|
return req.end(function(err, data) {
|
||||||
if (exited) {
|
if (exited) {
|
||||||
return;
|
return;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -872,7 +872,7 @@
|
||||||
timeout = setTimeout(function() {
|
timeout = setTimeout(function() {
|
||||||
exited = true;
|
exited = true;
|
||||||
return cb('Request has timed out');
|
return cb('Request has timed out');
|
||||||
}, 3e3);
|
}, 1e4);
|
||||||
return req.end(function(err, data) {
|
return req.end(function(err, data) {
|
||||||
if (exited) {
|
if (exited) {
|
||||||
return;
|
return;
|
||||||
|
|
File diff suppressed because one or more lines are too long
25
proxy.coffee
25
proxy.coffee
|
@ -13,40 +13,47 @@ config.host ?= 'api.github.com'
|
||||||
_.extend scrubbed = {}, config, { 'protocol': 'http', 'token': null }
|
_.extend scrubbed = {}, config, { 'protocol': 'http', 'token': null }
|
||||||
|
|
||||||
proxy = (req, res, next) ->
|
proxy = (req, res, next) ->
|
||||||
write = (code, body) ->
|
end = (code, body) ->
|
||||||
res.writeHead code, {'Content-Type': 'application/json; charset=utf-8'}
|
res.writeHead code, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
res.end body
|
res.end body
|
||||||
|
|
||||||
|
# Log it.
|
||||||
|
console.log new Date(), req.url
|
||||||
|
|
||||||
# Config?
|
# Config?
|
||||||
if req.url is '/config.json'
|
if req.url is '/config.json'
|
||||||
# Refer to us like so.
|
# Refer to us like so.
|
||||||
# Prefer custom header x-forwarded-host if defined.
|
# Prefer custom header x-forwarded-host if defined.
|
||||||
scrubbed.host = req.headers['x-forwarded-host'] or req.headers.host
|
scrubbed.host = req.headers['x-forwarded-host'] or req.headers.host
|
||||||
return write 200, JSON.stringify scrubbed, null, 4
|
return end 200, JSON.stringify scrubbed, null, 4
|
||||||
|
|
||||||
# API request?
|
# GitHub API request?
|
||||||
if req.url.match /^\/repos/
|
if req.url.match /^\/repos/
|
||||||
# The new headers.
|
# The default headers.
|
||||||
headers =
|
headers =
|
||||||
# See http://developer.github.com/v3/media/#beta-v3-and-the-future
|
# See http://developer.github.com/v3/media/#beta-v3-and-the-future
|
||||||
'Accept': 'application/vnd.github.v3'
|
'Accept': 'application/vnd.github.v3'
|
||||||
# See http://developer.github.com/v3/#user-agent-required
|
# See http://developer.github.com/v3/#user-agent-required
|
||||||
'User-Agent': 'GitHub-Burndown-Chart'
|
'User-Agent': 'GitHub-Burndown-Chart'
|
||||||
# Add a token?
|
# Add a token?
|
||||||
headers.Authorization = 'token ' + config.token if config.token
|
headers.Authorization = "token #{config.token}" if config.token?
|
||||||
|
|
||||||
# Make the HTTPS request.
|
# Make the HTTPS request.
|
||||||
return request {
|
return request {
|
||||||
'uri': 'https://' + config.host + req.url
|
'uri': "https://#{config.host}#{req.url}"
|
||||||
headers
|
headers
|
||||||
}, (_err, _res, body) ->
|
# Handle the response.
|
||||||
return write(500) if _err
|
}, (err, _res, body) ->
|
||||||
write _res.statusCode, body
|
return end(500) if err
|
||||||
|
end _res.statusCode, body
|
||||||
|
|
||||||
# Get handled by Connect.
|
# Get handled by Connect.
|
||||||
do next
|
do next
|
||||||
|
|
||||||
app = connect()
|
app = connect()
|
||||||
.use(proxy)
|
.use(proxy)
|
||||||
|
# Serve the public directory with the app, no need to launch another service.
|
||||||
.use(connect.static(__dirname + '/public'))
|
.use(connect.static(__dirname + '/public'))
|
||||||
|
# Connect on an env port or go random.
|
||||||
.listen process.env.PORT, ->
|
.listen process.env.PORT, ->
|
||||||
console.log 'Proxy listening on port', app.address().port
|
console.log 'Proxy listening on port', app.address().port
|
|
@ -0,0 +1 @@
|
||||||
|
!config.json
|
|
@ -0,0 +1 @@
|
||||||
|
../config.json
|
|
@ -66,7 +66,7 @@ request = ({ protocol, host, path, query, headers }, cb) ->
|
||||||
timeout = setTimeout ->
|
timeout = setTimeout ->
|
||||||
exited = yes
|
exited = yes
|
||||||
cb 'Request has timed out'
|
cb 'Request has timed out'
|
||||||
, 3e3
|
, 1e4 # give us 10s
|
||||||
|
|
||||||
# Send.
|
# Send.
|
||||||
req.end (err, data) ->
|
req.end (err, data) ->
|
||||||
|
|
Loading…
Reference in New Issue