diff --git a/README.md b/README.md
index fa242a26..3faacc33 100644
--- a/README.md
+++ b/README.md
@@ -22,9 +22,9 @@ $ bower install vue-resource
```
### CDN
-Available on [jsdelivr](https://cdn.jsdelivr.net/vue.resource/1.1.1/vue-resource.min.js), [cdnjs](https://cdnjs.com/libraries/vue-resource) or [unpkg](https://unpkg.com/vue-resource@1.1.1/dist/vue-resource.min.js).
+Available on [jsdelivr](https://cdn.jsdelivr.net/vue.resource/1.1.2/vue-resource.min.js), [cdnjs](https://cdnjs.com/libraries/vue-resource) or [unpkg](https://unpkg.com/vue-resource@1.1.2/dist/vue-resource.min.js).
```html
-
+
```
## Example
diff --git a/bower.json b/bower.json
index 8e7a5f8e..d9b7530f 100644
--- a/bower.json
+++ b/bower.json
@@ -1,7 +1,7 @@
{
"name": "vue-resource",
"main": "dist/vue-resource.js",
- "version": "1.1.1",
+ "version": "1.1.2",
"description": "The HTTP client for Vue.js",
"homepage": "https://github.com/vuejs/vue-resource",
"license": "MIT",
diff --git a/dist/vue-resource.common.js b/dist/vue-resource.common.js
index 367fc665..ccb25833 100644
--- a/dist/vue-resource.common.js
+++ b/dist/vue-resource.common.js
@@ -1,5 +1,5 @@
/*!
- * vue-resource v1.1.1
+ * vue-resource v1.1.2
* https://github.com/vuejs/vue-resource
* Released under the MIT License.
*/
@@ -270,6 +270,8 @@ var hasOwnProperty = ref.hasOwnProperty;
var ref$1 = [];
var slice = ref$1.slice;
+var inBrowser = typeof window !== 'undefined';
+
var Util = function (Vue) {
util = Vue.util;
debug = Vue.config.debug || !Vue.config.silent;
@@ -309,9 +311,7 @@ function isString(val) {
return typeof val === 'string';
}
-function isBoolean(val) {
- return val === true || val === false;
-}
+
function isFunction(val) {
return typeof val === 'function';
@@ -639,9 +639,6 @@ var template = function (options) {
* Service for URL templating.
*/
-var ie = document.documentMode;
-var el = document.createElement('a');
-
function Url(url, params) {
var self = this || {}, options$$1 = url, transform;
@@ -711,7 +708,9 @@ Url.params = function (obj) {
Url.parse = function (url) {
- if (ie) {
+ var el = document.createElement('a');
+
+ if (document.documentMode) {
el.href = url;
url = el.href;
}
@@ -801,34 +800,29 @@ var xdrClient = function (request) {
* CORS Interceptor.
*/
-var ORIGIN_URL = Url.parse(location.href);
-var SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest();
+var SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest();
var cors = function (request, next) {
- if (!isBoolean(request.crossOrigin) && crossOrigin(request)) {
- request.crossOrigin = true;
- }
+ if (inBrowser) {
- if (request.crossOrigin) {
+ var orgUrl = Url.parse(location.href);
+ var reqUrl = Url.parse(request.getUrl());
- if (!SUPPORTS_CORS) {
- request.client = xdrClient;
- }
+ if (reqUrl.protocol !== orgUrl.protocol || reqUrl.host !== orgUrl.host) {
- delete request.emulateHTTP;
+ request.crossOrigin = true;
+ request.emulateHTTP = false;
+
+ if (!SUPPORTS_CORS) {
+ request.client = xdrClient;
+ }
+ }
}
next();
};
-function crossOrigin(request) {
-
- var requestUrl = Url.parse(Url(request));
-
- return (requestUrl.protocol !== ORIGIN_URL.protocol || requestUrl.host !== ORIGIN_URL.host);
-}
-
/**
* Body Interceptor.
*/
diff --git a/dist/vue-resource.es2015.js b/dist/vue-resource.es2015.js
index f288f522..852f8c2c 100644
--- a/dist/vue-resource.es2015.js
+++ b/dist/vue-resource.es2015.js
@@ -1,5 +1,5 @@
/*!
- * vue-resource v1.1.1
+ * vue-resource v1.1.2
* https://github.com/vuejs/vue-resource
* Released under the MIT License.
*/
@@ -268,6 +268,8 @@ var hasOwnProperty = ref.hasOwnProperty;
var ref$1 = [];
var slice = ref$1.slice;
+var inBrowser = typeof window !== 'undefined';
+
var Util = function (Vue) {
util = Vue.util;
debug = Vue.config.debug || !Vue.config.silent;
@@ -307,9 +309,7 @@ function isString(val) {
return typeof val === 'string';
}
-function isBoolean(val) {
- return val === true || val === false;
-}
+
function isFunction(val) {
return typeof val === 'function';
@@ -637,9 +637,6 @@ var template = function (options) {
* Service for URL templating.
*/
-var ie = document.documentMode;
-var el = document.createElement('a');
-
function Url(url, params) {
var self = this || {}, options$$1 = url, transform;
@@ -709,7 +706,9 @@ Url.params = function (obj) {
Url.parse = function (url) {
- if (ie) {
+ var el = document.createElement('a');
+
+ if (document.documentMode) {
el.href = url;
url = el.href;
}
@@ -799,34 +798,29 @@ var xdrClient = function (request) {
* CORS Interceptor.
*/
-var ORIGIN_URL = Url.parse(location.href);
-var SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest();
+var SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest();
var cors = function (request, next) {
- if (!isBoolean(request.crossOrigin) && crossOrigin(request)) {
- request.crossOrigin = true;
- }
+ if (inBrowser) {
- if (request.crossOrigin) {
+ var orgUrl = Url.parse(location.href);
+ var reqUrl = Url.parse(request.getUrl());
- if (!SUPPORTS_CORS) {
- request.client = xdrClient;
- }
+ if (reqUrl.protocol !== orgUrl.protocol || reqUrl.host !== orgUrl.host) {
- delete request.emulateHTTP;
+ request.crossOrigin = true;
+ request.emulateHTTP = false;
+
+ if (!SUPPORTS_CORS) {
+ request.client = xdrClient;
+ }
+ }
}
next();
};
-function crossOrigin(request) {
-
- var requestUrl = Url.parse(Url(request));
-
- return (requestUrl.protocol !== ORIGIN_URL.protocol || requestUrl.host !== ORIGIN_URL.host);
-}
-
/**
* Body Interceptor.
*/
diff --git a/dist/vue-resource.js b/dist/vue-resource.js
index 803824de..56512c8b 100644
--- a/dist/vue-resource.js
+++ b/dist/vue-resource.js
@@ -1,5 +1,5 @@
/*!
- * vue-resource v1.1.1
+ * vue-resource v1.1.2
* https://github.com/vuejs/vue-resource
* Released under the MIT License.
*/
@@ -274,6 +274,8 @@ var hasOwnProperty = ref.hasOwnProperty;
var ref$1 = [];
var slice = ref$1.slice;
+var inBrowser = typeof window !== 'undefined';
+
var Util = function (Vue) {
util = Vue.util;
debug = Vue.config.debug || !Vue.config.silent;
@@ -313,9 +315,7 @@ function isString(val) {
return typeof val === 'string';
}
-function isBoolean(val) {
- return val === true || val === false;
-}
+
function isFunction(val) {
return typeof val === 'function';
@@ -643,9 +643,6 @@ var template = function (options) {
* Service for URL templating.
*/
-var ie = document.documentMode;
-var el = document.createElement('a');
-
function Url(url, params) {
var self = this || {}, options$$1 = url, transform;
@@ -715,7 +712,9 @@ Url.params = function (obj) {
Url.parse = function (url) {
- if (ie) {
+ var el = document.createElement('a');
+
+ if (document.documentMode) {
el.href = url;
url = el.href;
}
@@ -805,34 +804,29 @@ var xdrClient = function (request) {
* CORS Interceptor.
*/
-var ORIGIN_URL = Url.parse(location.href);
-var SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest();
+var SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest();
var cors = function (request, next) {
- if (!isBoolean(request.crossOrigin) && crossOrigin(request)) {
- request.crossOrigin = true;
- }
+ if (inBrowser) {
- if (request.crossOrigin) {
+ var orgUrl = Url.parse(location.href);
+ var reqUrl = Url.parse(request.getUrl());
- if (!SUPPORTS_CORS) {
- request.client = xdrClient;
- }
+ if (reqUrl.protocol !== orgUrl.protocol || reqUrl.host !== orgUrl.host) {
- delete request.emulateHTTP;
+ request.crossOrigin = true;
+ request.emulateHTTP = false;
+
+ if (!SUPPORTS_CORS) {
+ request.client = xdrClient;
+ }
+ }
}
next();
};
-function crossOrigin(request) {
-
- var requestUrl = Url.parse(Url(request));
-
- return (requestUrl.protocol !== ORIGIN_URL.protocol || requestUrl.host !== ORIGIN_URL.host);
-}
-
/**
* Body Interceptor.
*/
diff --git a/dist/vue-resource.min.js b/dist/vue-resource.min.js
index 61b1f5d5..cd821934 100644
--- a/dist/vue-resource.min.js
+++ b/dist/vue-resource.min.js
@@ -1,7 +1,7 @@
/*!
- * vue-resource v1.1.1
+ * vue-resource v1.1.2
* https://github.com/vuejs/vue-resource
* Released under the MIT License.
*/
-!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueResource=e()}(this,function(){"use strict";function t(t){this.state=W,this.value=void 0,this.deferred=[];var e=this;try{t(function(t){e.resolve(t)},function(t){e.reject(t)})}catch(t){e.reject(t)}}function e(t,e){t instanceof Promise?this.promise=t:this.promise=new Promise(t.bind(e)),this.context=e}function n(t){"undefined"!=typeof console&&_&&console.warn("[VueResource warn]: "+t)}function o(t){"undefined"!=typeof console&&console.error(t)}function r(t,e){return z.nextTick(t,e)}function i(t){return t?t.replace(/^\s*|\s*$/g,""):""}function u(t){return t?t.toLowerCase():""}function s(t){return t?t.toUpperCase():""}function c(t){return"string"==typeof t}function a(t){return t===!0||t===!1}function f(t){return"function"==typeof t}function p(t){return null!==t&&"object"==typeof t}function h(t){return p(t)&&Object.getPrototypeOf(t)==Object.prototype}function l(t){return"undefined"!=typeof Blob&&t instanceof Blob}function d(t){return"undefined"!=typeof FormData&&t instanceof FormData}function m(t,n,o){var r=e.resolve(t);return arguments.length<2?r:r.then(n,o)}function y(t,e,n){return n=n||{},f(n)&&(n=n.call(e)),b(t.bind({$vm:e,$options:n}),t,{$options:n})}function v(t,e){var n,o;if(et(t))for(n=0;n=200&&r<300,this.status=r||0,this.statusText=i||"",this.headers=new Tt(o),this.body=t,c(t)?this.bodyText=t:l(t)&&(this.bodyBlob=t,q(t)&&(this.bodyText=B(t)))};xt.prototype.blob=function(){return m(this.bodyBlob)},xt.prototype.text=function(){return m(this.bodyText)},xt.prototype.json=function(){return m(this.text(),function(t){return JSON.parse(t)})};var jt=function(t){this.body=null,this.params={},nt(this,t,{method:s(t.method||"GET")}),this.headers instanceof Tt||(this.headers=new Tt(this.headers))};jt.prototype.getUrl=function(){return A(this)},jt.prototype.getBody=function(){return this.body},jt.prototype.respondWith=function(t,e){return new xt(t,nt(e||{},{url:this.getUrl()}))};var Et={"X-Requested-With":"XMLHttpRequest"},Ot={Accept:"application/json, text/plain, */*"},Pt={"Content-Type":"application/json;charset=utf-8"};return N.options={},N.headers={put:Pt,post:Pt,patch:Pt,delete:Pt,custom:Et,common:Ot},N.interceptors=[mt,yt,ht,dt,vt,pt],["get","delete","head","jsonp"].forEach(function(t){N[t]=function(e,n){return this(nt(n||{},{url:e,method:t}))}}),["post","put","patch"].forEach(function(t){N[t]=function(e,n,o){return this(nt(o||{},{url:e,method:t,body:n}))}}),D.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},update:{method:"PUT"},remove:{method:"DELETE"},delete:{method:"DELETE"}},"undefined"!=typeof window&&window.Vue&&window.Vue.use(J),J});
\ No newline at end of file
+!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueResource=e()}(this,function(){"use strict";function t(t){this.state=M,this.value=void 0,this.deferred=[];var e=this;try{t(function(t){e.resolve(t)},function(t){e.reject(t)})}catch(t){e.reject(t)}}function e(t,e){t instanceof Promise?this.promise=t:this.promise=new Promise(t.bind(e)),this.context=e}function n(t){"undefined"!=typeof console&&G&&console.warn("[VueResource warn]: "+t)}function o(t){"undefined"!=typeof console&&console.error(t)}function r(t,e){return V.nextTick(t,e)}function i(t){return t?t.replace(/^\s*|\s*$/g,""):""}function u(t){return t?t.toLowerCase():""}function s(t){return t?t.toUpperCase():""}function c(t){return"string"==typeof t}function a(t){return"function"==typeof t}function f(t){return null!==t&&"object"==typeof t}function p(t){return f(t)&&Object.getPrototypeOf(t)==Object.prototype}function h(t){return"undefined"!=typeof Blob&&t instanceof Blob}function l(t){return"undefined"!=typeof FormData&&t instanceof FormData}function d(t,n,o){var r=e.resolve(t);return arguments.length<2?r:r.then(n,o)}function m(t,e,n){return n=n||{},a(n)&&(n=n.call(e)),v(t.bind({$vm:e,$options:n}),t,{$options:n})}function y(t,e){var n,o;if(tt(t))for(n=0;n=200&&r<300,this.status=r||0,this.statusText=i||"",this.headers=new vt(o),this.body=t,c(t)?this.bodyText=t:h(t)&&(this.bodyBlob=t,L(t)&&(this.bodyText=H(t)))};bt.prototype.blob=function(){return d(this.bodyBlob)},bt.prototype.text=function(){return d(this.bodyText)},bt.prototype.json=function(){return d(this.text(),function(t){return JSON.parse(t)})};var gt=function(t){this.body=null,this.params={},et(this,t,{method:s(t.method||"GET")}),this.headers instanceof vt||(this.headers=new vt(this.headers))};gt.prototype.getUrl=function(){return C(this)},gt.prototype.getBody=function(){return this.body},gt.prototype.respondWith=function(t,e){return new bt(t,et(e||{},{url:this.getUrl()}))};var wt={"X-Requested-With":"XMLHttpRequest"},Tt={Accept:"application/json, text/plain, */*"},xt={"Content-Type":"application/json;charset=utf-8"};return B.options={},B.headers={put:xt,post:xt,patch:xt,delete:xt,custom:wt,common:Tt},B.interceptors=[pt,ht,ct,ft,lt,st],["get","delete","head","jsonp"].forEach(function(t){B[t]=function(e,n){return this(et(n||{},{url:e,method:t}))}}),["post","put","patch"].forEach(function(t){B[t]=function(e,n,o){return this(et(o||{},{url:e,method:t,body:n}))}}),q.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},update:{method:"PUT"},remove:{method:"DELETE"},delete:{method:"DELETE"}},"undefined"!=typeof window&&window.Vue&&window.Vue.use(D),D});
\ No newline at end of file
diff --git a/package.json b/package.json
index 426a8db7..705eddff 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-resource",
- "version": "1.1.1",
+ "version": "1.1.2",
"main": "dist/vue-resource.common.js",
"jsnext:main": "dist/vue-resource.es2015.js",
"description": "The HTTP client for Vue.js",
diff --git a/src/http/interceptor/cors.js b/src/http/interceptor/cors.js
index 243fef3a..0a41f03a 100644
--- a/src/http/interceptor/cors.js
+++ b/src/http/interceptor/cors.js
@@ -4,32 +4,27 @@
import Url from '../../url/index';
import xdrClient from '../client/xdr';
-import { isBoolean } from '../../util';
+import { inBrowser } from '../../util';
-const ORIGIN_URL = Url.parse(location.href);
-const SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest();
+const SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest();
export default function (request, next) {
- if (!isBoolean(request.crossOrigin) && crossOrigin(request)) {
- request.crossOrigin = true;
- }
+ if (inBrowser) {
- if (request.crossOrigin) {
+ var orgUrl = Url.parse(location.href);
+ var reqUrl = Url.parse(request.getUrl());
- if (!SUPPORTS_CORS) {
- request.client = xdrClient;
- }
+ if (reqUrl.protocol !== orgUrl.protocol || reqUrl.host !== orgUrl.host) {
- delete request.emulateHTTP;
+ request.crossOrigin = true;
+ request.emulateHTTP = false;
+
+ if (!SUPPORTS_CORS) {
+ request.client = xdrClient;
+ }
+ }
}
next();
}
-
-function crossOrigin(request) {
-
- var requestUrl = Url.parse(Url(request));
-
- return (requestUrl.protocol !== ORIGIN_URL.protocol || requestUrl.host !== ORIGIN_URL.host);
-}
diff --git a/src/url/index.js b/src/url/index.js
index 8ce275ee..f2fffec5 100644
--- a/src/url/index.js
+++ b/src/url/index.js
@@ -2,9 +2,6 @@
* Service for URL templating.
*/
-const ie = document.documentMode;
-const el = document.createElement('a');
-
import root from './root';
import query from './query';
import template from './template';
@@ -79,7 +76,9 @@ Url.params = function (obj) {
Url.parse = function (url) {
- if (ie) {
+ var el = document.createElement('a');
+
+ if (document.documentMode) {
el.href = url;
url = el.href;
}
diff --git a/src/util.js b/src/util.js
index 018e8320..ecef6a7d 100644
--- a/src/util.js
+++ b/src/util.js
@@ -6,6 +6,8 @@ import Promise from './promise';
var debug = false, util = {}, {hasOwnProperty} = {}, {slice} = [];
+export const inBrowser = typeof window !== 'undefined';
+
export default function (Vue) {
util = Vue.util;
debug = Vue.config.debug || !Vue.config.silent;