Share request settings between request and pinejs-client, and make sure a 30s timeout is used.

This commit is contained in:
Pagan Gazzard 2015-03-12 16:36:24 +00:00 committed by Pablo Carranza Vélez
parent c29e0720c6
commit 84b5746111
4 changed files with 19 additions and 14 deletions

View File

@ -5,16 +5,13 @@ path = require 'path'
config = require './config'
dockerUtils = require './docker-utils'
Promise = require 'bluebird'
PlatformAPI = require 'pinejs-client'
utils = require './utils'
tty = require './lib/tty'
logger = require './lib/logger'
{ resinApi, cachedResinApi } = require './request'
{docker} = dockerUtils
PLATFORM_ENDPOINT = url.resolve(config.apiEndpoint, '/ewa/')
resinApi = new PlatformAPI(PLATFORM_ENDPOINT)
cachedResinApi = resinApi.clone({}, cache: {})
knex('config').select('value').where(key: 'uuid').then ([ uuid ]) ->
logger.init(

View File

@ -1,16 +1,11 @@
Promise = require 'bluebird'
_ = require 'lodash'
url = require 'url'
knex = require './db'
utils = require './utils'
crypto = require 'crypto'
config = require './config'
PlatformAPI = require 'pinejs-client'
{ resinApi } = require './request'
fs = Promise.promisifyAll(require('fs'))
PLATFORM_ENDPOINT = url.resolve(config.apiEndpoint, '/ewa/')
resinApi = new PlatformAPI(PLATFORM_ENDPOINT)
registerDevice = (apiKey, userId, applicationId, deviceType, uuid) ->
# I'd be nice if the UUID matched the output of a SHA-256 function, but although the length limit of the CN
# attribute in a X.509 certificate is 64 chars, a 32 byte UUID (64 chars in hex) doesn't pass the certificate

View File

@ -6,7 +6,7 @@ es = require 'event-stream'
_ = require 'lodash'
knex = require './db'
request = require './request'
{ request } = require './request'
docker = Promise.promisifyAll(new Docker(socketPath: config.dockerSocket))
# Hack dockerode to promisify internal classes' prototypes

View File

@ -1,7 +1,20 @@
request = require 'request'
config = require './config'
PlatformAPI = require 'pinejs-client'
Promise = require 'bluebird'
request = require 'request'
url = require 'url'
request = request.defaults
requestOpts =
gzip: true
timeout: 30000
module.exports = Promise.promisifyAll(request)
PLATFORM_ENDPOINT = url.resolve(config.apiEndpoint, '/ewa/')
exports.resinApi = resinApi = new PlatformAPI
apiPrefix: PLATFORM_ENDPOINT
passthrough: requestOpts
exports.cachedResinApi = resinApi.clone({}, cache: {})
request = request.defaults(requestOpts)
exports.request = Promise.promisifyAll(request)