mirror of
https://github.com/donl/slouch.git
synced 2026-05-25 22:07:24 -06:00
* Pass slouch in when instantiating EnhancedRequest This is to allow EnhanceRequest to access slouch._requestWrapper.setCookie * Update locally stored cookie when response has set-cookie header * Delete unused this._cookie * Fix cookie-authentication in browser * Fix test Request header now always include withCredentials: true * Fix test EnhancedRequest constructor now requires instance of Slouch * Typo * Fix test * Remove TODO comment and clean up redundant code * Revert change to user.js * Fix user test spec * Fix user test spec * Fix browser coverage test fail * FIx beautify test fail * Fix failed jshint test
55 lines
2 KiB
JavaScript
55 lines
2 KiB
JavaScript
'use strict';
|
|
|
|
var Attachment = require('./attachment'),
|
|
Config = require('./config'),
|
|
DB = require('./db'),
|
|
Doc = require('./doc'),
|
|
ExcludeDesignDocsIterator = require('./exclude-design-docs-iterator'),
|
|
Membership = require('./membership'),
|
|
NotAuthenticatedError = require('./not-authenticated-error'),
|
|
Security = require('./security'),
|
|
System = require('./system'),
|
|
User = require('./user'),
|
|
EnhancedRequest = require('./enhanced-request'),
|
|
RequestWrapper = require('./request-wrapper');
|
|
|
|
var Slouch = function (url) {
|
|
this._url = url;
|
|
|
|
// Package request so that we can inject a cookie, provide promises and better built-in logic
|
|
this._requestWrapper = new RequestWrapper();
|
|
this._request = this._requestWrapper.requestFactory();
|
|
this._enhancedRequest = new EnhancedRequest(this);
|
|
|
|
// Shorthand so that can just issue _slouch.req() in different modules
|
|
this._req = this._requestFactory();
|
|
|
|
this.attachment = new Attachment(this);
|
|
this.config = new Config(this);
|
|
this.db = new DB(this);
|
|
this.doc = new Doc(this);
|
|
this.ExcludeDesignDocsIterator = ExcludeDesignDocsIterator;
|
|
this.system = new System(this);
|
|
this.membership = new Membership(this);
|
|
this.NotAuthenticatedError = NotAuthenticatedError;
|
|
this.security = new Security(this);
|
|
this.user = new User(this);
|
|
|
|
// When continuously listening to a CouchDB stream our stream can just deadlock, even when we
|
|
// specify a heartbeat=60s. This rarely happens, about once a week, but when it does it can cause
|
|
// major issues for users. It isn't clear if this issue is at the CouchDB, AWS load balancer or
|
|
// Slouch layer as there are no errors generated, but we can avoid it by simply reconnecting
|
|
// periodically.
|
|
this.forceReconnectAfterMilliseconds = Slouch.DEFAULT_FORCE_RECONNECT_AFTER_MILLISECONDS;
|
|
};
|
|
|
|
Slouch.DEFAULT_FORCE_RECONNECT_AFTER_MILLISECONDS = 300000;
|
|
|
|
Slouch.prototype._requestFactory = function () {
|
|
var self = this;
|
|
return function () {
|
|
return self._enhancedRequest.request.apply(self._enhancedRequest, arguments);
|
|
};
|
|
};
|
|
|
|
module.exports = Slouch;
|