Instantiate appropriate HttpImpl
* src/dapi/DataApiFactory.js (fromType): Instantiate NodeHttpImpl when XMLHttpRequest is undefined.master
parent
624f35a489
commit
a1d5e7d3c5
|
@ -19,14 +19,14 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Class = require( 'easejs' ).Class,
|
const Class = require( 'easejs' ).Class;
|
||||||
|
const HttpDataApi = require( './http/HttpDataApi' );
|
||||||
HttpDataApi = require( './http/HttpDataApi' ),
|
const XhrHttpImpl = require( './http/XhrHttpImpl' );
|
||||||
XhrHttpImpl = require( './http/XhrHttpImpl' ),
|
const NodeHttpImpl = require( './http/NodeHttpImpl' );
|
||||||
JsonResponse = require( './format/JsonResponse' ),
|
const JsonResponse = require( './format/JsonResponse' );
|
||||||
RestrictedDataApi = require( './RestrictedDataApi' ),
|
const RestrictedDataApi = require( './RestrictedDataApi' );
|
||||||
StaticAdditionDataApi = require( './StaticAdditionDataApi' ),
|
const StaticAdditionDataApi = require( './StaticAdditionDataApi' );
|
||||||
BucketDataApi = require( './BucketDataApi' );
|
const BucketDataApi = require( './BucketDataApi' );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,10 +58,20 @@ module.exports = Class( 'DataApiFactory',
|
||||||
switch ( type )
|
switch ( type )
|
||||||
{
|
{
|
||||||
case 'rest':
|
case 'rest':
|
||||||
|
const impl = ( typeof XMLHttpRequest !== 'undefined' )
|
||||||
|
? XhrHttpImpl( XMLHttpRequest )
|
||||||
|
: NodeHttpImpl(
|
||||||
|
{
|
||||||
|
http: require( 'http' ),
|
||||||
|
https: require( 'https' ),
|
||||||
|
},
|
||||||
|
require( 'url' )
|
||||||
|
);
|
||||||
|
|
||||||
api = HttpDataApi.use( JsonResponse )(
|
api = HttpDataApi.use( JsonResponse )(
|
||||||
source,
|
source,
|
||||||
method.toUpperCase(),
|
method.toUpperCase(),
|
||||||
XhrHttpImpl( XMLHttpRequest )
|
impl
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue