isomorphic-fetch-http
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -32,34 +32,31 @@ 'use strict'; | ||
var $http = function () { | ||
function $http() { | ||
_classCallCheck(this, $http); | ||
var _http = function () { | ||
function _http() { | ||
_classCallCheck(this, _http); | ||
// bind this | ||
this.prefix = ""; | ||
this.header = {}; | ||
this.fn = function (data) { | ||
return data; | ||
}; | ||
// this.$get = this.$get.bind(this); | ||
// this.$post = this.$post.bind(this); | ||
// this.$put = this.$put.bind(this); | ||
// this.$delete = this.$delete.bind(this); | ||
// this.$option = this.$option.bind(this); | ||
this[config] = { | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Max-Age": "86400", | ||
"Access-Control-Allow-Methods": "POST, GET, OPTIONS, PUT, DELETE", | ||
"Access-Control-Allow-Headers": "token, host, x-real-ip, x-forwarded-ip, accept, content-type" | ||
}, | ||
credentials: "include", | ||
client_max_body_size: "2048m" | ||
}; | ||
} | ||
_createClass($http, [{ | ||
key: 'contructor', | ||
value: function contructor() { | ||
// bind this | ||
this.prefix = ""; | ||
this.header = {}; | ||
this.fn = function (data) { | ||
return data; | ||
}; | ||
this.$get = this.$get.bind(this); | ||
this.$post = this.$post.bind(this); | ||
this.$put = this.$put.bind(this); | ||
this.$delete = this.$delete.bind(this); | ||
this.$option = this.$option.bind(this); | ||
this[config] = { | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Max-Age": "86400", | ||
"Access-Control-Allow-Methods": "POST, GET, OPTIONS, PUT, DELETE", | ||
"Access-Control-Allow-Headers": "token, host, x-real-ip, x-forwarded-ip, accept, content-type" | ||
}, | ||
credentials: "include", | ||
client_max_body_size: "2048m" | ||
}; | ||
} | ||
}, { | ||
_createClass(_http, [{ | ||
key: http, | ||
@@ -87,5 +84,7 @@ value: function value(url) { | ||
key: 'setup', | ||
value: function setup(prefix) { | ||
var header = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var fn = arguments[2]; | ||
value: function setup(_ref) { | ||
var prefix = _ref.prefix, | ||
_ref$header = _ref.header, | ||
header = _ref$header === undefined ? {} : _ref$header, | ||
fn = _ref.fn; | ||
@@ -97,31 +96,31 @@ this.prefix = prefix; | ||
}, { | ||
key: '$get', | ||
value: function $get(url, param) { | ||
key: 'get', | ||
value: function get(url, param) { | ||
return this[http](url + '?' + (0, _qs.stringify)(param)); | ||
} | ||
}, { | ||
key: '$post', | ||
value: function $post(url, param) { | ||
key: 'post', | ||
value: function post(url, param) { | ||
return this[http](url, { method: 'POST', body: (0, _qs.stringify)(param) }); | ||
} | ||
}, { | ||
key: '$put', | ||
value: function $put(url, param) { | ||
key: 'put', | ||
value: function put(url, param) { | ||
return this[http](url, { method: 'PUT', body: (0, _qs.stringify)(param) }); | ||
} | ||
}, { | ||
key: '$delete', | ||
value: function $delete(url, param) { | ||
key: 'delete', | ||
value: function _delete(url, param) { | ||
return this[http](url + '?' + (0, _qs.stringify)(param), { method: 'DELETE' }); | ||
} | ||
}, { | ||
key: '$option', | ||
value: function $option(url, param) { | ||
return $http(url, { method: 'POST', body: JSON.stringify(param) }, { "Content-Type": "application/json" }); | ||
key: 'option', | ||
value: function option(url, param) { | ||
return this[http](url, { method: 'POST', body: JSON.stringify(param) }, { "Content-Type": "application/json" }); | ||
} | ||
}]); | ||
return $http; | ||
return _http; | ||
}(); | ||
exports.default = new $http(); | ||
exports.default = new _http(); |
{ | ||
"name": "isomorphic-fetch-http", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "react fetch by isomorphic-fetch", | ||
@@ -10,3 +10,5 @@ "main": "lib/isomorphic-fetch-http.js", | ||
"build": "babel src --out-dir lib --extensions .js,.es6 --copy-files", | ||
"lint": "eslint --color --config .eslintrc src/*" | ||
"lint": "eslint --color --config .eslintrc src/*", | ||
"pretest": "babel src --out-dir test --extensions .js,.es6 --copy-files", | ||
"test": "webpack-dev-server --config webpack.config.test.js --devtool eval --port 8989 --host 0.0.0.0 --hot --progress --open --content-base test" | ||
}, | ||
@@ -32,5 +34,7 @@ "repository": { | ||
"babel-plugin-transform-runtime": "^6.15.0", | ||
"babel-polyfill": "^6.13.0", | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-preset-react": "^6.16.0", | ||
"babel-preset-stage-0": "^6.16.0", | ||
"babel-runtime": "^6.11.6", | ||
"eslint": "3.1.1", | ||
@@ -43,3 +47,6 @@ "eslint-config-standard": "5.3.5", | ||
"eslint-plugin-standard": "2.0.0", | ||
"rimraf": "^2.5.4" | ||
"file-loader": "^0.9.0", | ||
"rimraf": "^2.5.4", | ||
"webpack": "^1.13.2", | ||
"webpack-dev-server": "^1.15.2" | ||
}, | ||
@@ -46,0 +53,0 @@ "dependencies": { |
@@ -14,4 +14,4 @@ import fetch from 'isomorphic-fetch'; | ||
*/ | ||
class $http { | ||
contructor() { | ||
class _http { | ||
constructor() { | ||
// bind this | ||
@@ -21,7 +21,7 @@ this.prefix = ""; | ||
this.fn = (data) => data; | ||
this.$get = this.$get.bind(this); | ||
this.$post = this.$post.bind(this); | ||
this.$put = this.$put.bind(this); | ||
this.$delete = this.$delete.bind(this); | ||
this.$option = this.$option.bind(this); | ||
// this.$get = this.$get.bind(this); | ||
// this.$post = this.$post.bind(this); | ||
// this.$put = this.$put.bind(this); | ||
// this.$delete = this.$delete.bind(this); | ||
// this.$option = this.$option.bind(this); | ||
this[config] = { | ||
@@ -59,3 +59,3 @@ headers: { | ||
setup(prefix, header = {}, fn) { | ||
setup({prefix, header = {}, fn}) { | ||
this.prefix = prefix; | ||
@@ -66,23 +66,23 @@ this.header = header; | ||
$get(url, param) { | ||
get(url, param) { | ||
return this[http](`${url}?${stringify(param)}`); | ||
} | ||
$post(url, param) { | ||
post(url, param) { | ||
return this[http](url, { method: 'POST', body: stringify(param) }); | ||
} | ||
$put(url, param) { | ||
put(url, param) { | ||
return this[http](url, { method: 'PUT', body: stringify(param) }); | ||
} | ||
$delete(url, param) { | ||
delete(url, param) { | ||
return this[http](`${url}?${stringify(param)}`, { method: 'DELETE' }); | ||
} | ||
$option(url, param) { | ||
return $http(url, { method: 'POST', body: JSON.stringify(param) }, {"Content-Type": "application/json"}); | ||
option(url, param) { | ||
return this[http](url, { method: 'POST', body: JSON.stringify(param) }, {"Content-Type": "application/json"}); | ||
} | ||
} | ||
export default new $http(); | ||
export default new _http(); |
15782
12
332
21