@nuxtjs/axios
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -6,2 +6,14 @@ # Change Log | ||
<a name="2.0.3"></a> | ||
## [2.0.3](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.0.2...@nuxtjs/axios@2.0.3) (2017-06-10) | ||
### Bug Fixes | ||
* **axios:** Handle relative baseURL ([19b8453](https://github.com/nuxt/modules/commit/19b8453)) | ||
* handle 0.0.0.0 host ([610e0f5](https://github.com/nuxt/modules/commit/610e0f5)) | ||
<a name="2.0.2"></a> | ||
@@ -8,0 +20,0 @@ ## [2.0.2](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.0.1...@nuxtjs/axios@2.0.2) (2017-06-09) |
20
index.js
const chalk = require('chalk') | ||
const path = require('path') | ||
const { hostname } = require('os') | ||
const { URL } = require('whatwg-url') | ||
const port = process.env.PORT || process.env.npm_package_config_nuxt_port || 3000 | ||
const host = process.env.HOST || process.env.npm_package_config_nuxt_host || 'localhost' | ||
let host = process.env.HOST || process.env.npm_package_config_nuxt_host || 'localhost' | ||
if (host === '0.0.0.0') { | ||
host = hostname() | ||
} | ||
module.exports = function nuxtAxios (moduleOptions) { | ||
// Apply defaults | ||
const options = Object.assign({ | ||
const defaults = { | ||
baseURL: `http://${host}:${port}/api`, | ||
@@ -15,4 +19,7 @@ browserBaseURL: null, | ||
proxyHeaders: true | ||
}, this.options.axios, moduleOptions) | ||
} | ||
const options = Object.assign({}, defaults, this.options.axios, moduleOptions) | ||
// Override env | ||
if (process.env.API_URL) { | ||
@@ -26,6 +33,7 @@ options.baseURL = process.env.API_URL | ||
options.baseURL = new URL(options.baseURL, `http://${host}:${port}`) | ||
if (!options.browserBaseURL) { | ||
const url = new URL(options.baseURL) | ||
const sameHost = url.host === `${host}:${port}` | ||
options.browserBaseURL = sameHost ? url.pathname : options.url | ||
const sameHost = options.baseURL.host === `${host}:${port}` | ||
options.browserBaseURL = sameHost ? options.baseURL.pathname : options.baseURL | ||
} | ||
@@ -32,0 +40,0 @@ |
{ | ||
"name": "@nuxtjs/axios", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# Axios | ||
[![npm](https://img.shields.io/npm/dt/@nuxtjs/axios.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/axios) | ||
[![npm (scoped with tag)](https://img.shields.io/npm/v/@nuxtjs/axios/latest.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/axios) | ||
> Use [axios](https://github.com/mzabriskie/axios) with deep Nuxt integration and no pain! | ||
@@ -13,7 +16,18 @@ | ||
- Add `@nuxtjs/axios` dependency using yarn or npm to your project | ||
- Add `@nuxtjs/axios` module to `nuxt.config.js`: | ||
- Add `@nuxtjs/axios` to `modules` section of `nuxt.config.js` | ||
```js | ||
{ | ||
modules: [ | ||
'@nuxtjs/axios' | ||
] | ||
// Simple usage | ||
'@nuxtjs/axios', | ||
// With options | ||
['@nuxtjs/axios', { credentials: false }], | ||
], | ||
// You can optionally use global options instead of inline form | ||
axios: { | ||
credentials: false | ||
} | ||
} | ||
```` | ||
@@ -90,3 +104,3 @@ | ||
## Options | ||
You can pass options using module options or `axios` section in `nuxt.config.js`: | ||
You can pass options using module options or `axios` section in `nuxt.config.js` | ||
@@ -133,3 +147,3 @@ ### `baseURL` | ||
'@nuxtjs/proxy' | ||
], | ||
], | ||
proxy: [ | ||
@@ -136,0 +150,0 @@ ['/api', { target: 'http://www.mocky.io', pathRewrite: { '^/api': '/v2' } }] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13633
166
179