├── .github ├── ISSUE_TEMPLATE.md └── workflows │ └── ci.yml ├── renovate.json ├── docs ├── static │ ├── icon.png │ ├── favicon.ico │ ├── preview.png │ ├── preview-dark.png │ ├── async-data-with-nuxtjs.png │ ├── async-data-with-nuxtjs-2x.png │ ├── logo-dark.svg │ └── logo-light.svg ├── .gitignore ├── tailwind.config.js ├── content │ ├── settings.json │ └── en │ │ ├── migration.md │ │ ├── extend.md │ │ ├── setup.md │ │ ├── index.md │ │ ├── usage.md │ │ ├── helpers.md │ │ └── options.md ├── nuxt.config.js ├── package.json └── components │ └── global │ └── PromoteBlock.vue ├── .eslintignore ├── .gitignore ├── types ├── vuex.d.ts └── index.d.ts ├── .eslintrc.js ├── babel.config.js ├── test ├── fixture │ ├── api │ │ ├── cookie.js │ │ └── echo.js │ ├── plugins │ │ └── axios.js │ ├── pages │ │ ├── asyncData.vue │ │ ├── mounted.vue │ │ ├── cancelToken.vue │ │ ├── cookie.vue │ │ └── ssr.vue │ ├── store │ │ └── index.js │ └── nuxt.config.js └── axios.test.js ├── netlify.toml ├── .editorconfig ├── jest.config.js ├── LICENSE ├── package.json ├── README.md ├── lib ├── module.js └── plugin.js └── CHANGELOG.md /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "@nuxtjs" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /docs/static/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuxt-community/axios-module/HEAD/docs/static/icon.png -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # Common 2 | node_modules 3 | dist 4 | .nuxt 5 | coverage 6 | 7 | # Plugin 8 | lib/plugin.js 9 | -------------------------------------------------------------------------------- /docs/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuxt-community/axios-module/HEAD/docs/static/favicon.ico -------------------------------------------------------------------------------- /docs/static/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuxt-community/axios-module/HEAD/docs/static/preview.png -------------------------------------------------------------------------------- /docs/static/preview-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuxt-community/axios-module/HEAD/docs/static/preview-dark.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.iml 3 | .idea 4 | *.log* 5 | .nuxt 6 | .vscode 7 | .DS_Store 8 | coverage 9 | dist 10 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.iml 3 | .idea 4 | *.log* 5 | .nuxt 6 | .vscode 7 | .DS_Store 8 | coverage 9 | dist 10 | sw.js 11 | -------------------------------------------------------------------------------- /docs/static/async-data-with-nuxtjs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuxt-community/axios-module/HEAD/docs/static/async-data-with-nuxtjs.png -------------------------------------------------------------------------------- /docs/static/async-data-with-nuxtjs-2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuxt-community/axios-module/HEAD/docs/static/async-data-with-nuxtjs-2x.png -------------------------------------------------------------------------------- /types/vuex.d.ts: -------------------------------------------------------------------------------- 1 | import { NuxtAxiosInstance } from '.' 2 | 3 | declare module 'vuex/types/index' { 4 | interface Store { 5 | $axios: NuxtAxiosInstance, 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parserOptions: { 4 | parser: 'babel-eslint', 5 | sourceType: 'module' 6 | }, 7 | extends: [ 8 | '@nuxtjs' 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | [ 4 | '@babel/preset-env', { 5 | targets: { 6 | esmodules: true 7 | } 8 | } 9 | ] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixture/api/cookie.js: -------------------------------------------------------------------------------- 1 | export default (req, res) => { 2 | const reqCookie = (new URLSearchParams(req.headers.cookie || '').get('mycookie') || '').split(';')[0].trim() 3 | res.end(reqCookie || '') 4 | } 5 | -------------------------------------------------------------------------------- /docs/tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | future: { 3 | removeDeprecatedGapUtilities: true, 4 | purgeLayersByDefault: true, 5 | defaultLineHeights: true, 6 | standardFontWeights: true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | # https://docs.netlify.com/configure-builds/file-based-configuration 2 | 3 | [build] 4 | base = "docs" 5 | command = "yarn generate" 6 | publish = "dist" 7 | ignore = "git diff --quiet HEAD^ HEAD . ../package.json" 8 | -------------------------------------------------------------------------------- /test/fixture/plugins/axios.js: -------------------------------------------------------------------------------- 1 | export default function ({ $axios }) { 2 | $axios.onRequest((config) => { 3 | // eslint-disable-next-line no-console 4 | console.log('SPY: ' + config.url) 5 | 6 | $axios.defaults.xsrfHeaderName = 'X-CSRF-TOKEN' 7 | }) 8 | } 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_size = 2 6 | indent_style = space 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /docs/content/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Axios Module", 3 | "url": "https://axios.nuxtjs.org", 4 | "logo": { 5 | "light": "/logo-light.svg", 6 | "dark": "/logo-dark.svg" 7 | }, 8 | "github": "nuxt-community/axios-module", 9 | "twitter": "@nuxt_js" 10 | } 11 | -------------------------------------------------------------------------------- /test/fixture/pages/asyncData.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 17 | -------------------------------------------------------------------------------- /test/fixture/store/index.js: -------------------------------------------------------------------------------- 1 | export default { 2 | actions: { 3 | nuxtServerInit ({ commit }, ctx) { 4 | if (!ctx.$axios) { 5 | throw new Error('$axios is not defined!') 6 | } 7 | 8 | if (!ctx.app.$axios) { 9 | throw new Error('$axios is not defined!') 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /docs/nuxt.config.js: -------------------------------------------------------------------------------- 1 | import theme from '@nuxt/content-theme-docs' 2 | 3 | export default theme({ 4 | docs: { 5 | primaryColor: '#AA7AB5' 6 | }, 7 | buildModules: ['vue-plausible'], 8 | plausible: { 9 | domain: 'axios.nuxtjs.org' 10 | }, 11 | pwa: { 12 | manifest: { 13 | name: 'Nuxt Axios' 14 | } 15 | } 16 | }) 17 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docs", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "nuxt", 7 | "build": "nuxt build", 8 | "start": "nuxt start", 9 | "generate": "nuxt generate" 10 | }, 11 | "dependencies": { 12 | "@nuxt/content-theme-docs": "^0.11.1", 13 | "nuxt": "^2.15.8" 14 | }, 15 | "devDependencies": { 16 | "vue-plausible": "^1.3.1" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: 'node', 3 | collectCoverage: true, 4 | collectCoverageFrom: [ 5 | 'lib/**/*.js', 6 | '!lib/plugin.js' 7 | ], 8 | moduleNameMapper: { 9 | '^~/(.*)$': '/lib/$1', 10 | '^~~$': '', 11 | '^@@$': '', 12 | '^@/(.*)$': '/lib/$1' 13 | }, 14 | transform: { 15 | '^.+\\.js$': 'babel-jest' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/fixture/api/echo.js: -------------------------------------------------------------------------------- 1 | export default async (req, res) => { 2 | const query = new URL(req.url, 'http://localhost:3000').query 3 | if (query && query.delay) { 4 | await sleep(query.delay) 5 | } 6 | 7 | res.end(JSON.stringify({ 8 | url: req.url, 9 | method: req.method 10 | })) 11 | } 12 | 13 | function sleep (ms) { 14 | return new Promise((resolve) => { 15 | setTimeout(resolve, ms) 16 | }) 17 | } 18 | -------------------------------------------------------------------------------- /test/fixture/pages/mounted.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 21 | -------------------------------------------------------------------------------- /test/fixture/nuxt.config.js: -------------------------------------------------------------------------------- 1 | const { resolve } = require('path') 2 | 3 | module.exports = { 4 | rootDir: resolve(__dirname, '../..'), 5 | buildDir: resolve(__dirname, '.nuxt'), 6 | srcDir: __dirname, 7 | render: { 8 | resourceHints: false 9 | }, 10 | modules: [ 11 | { handler: require('../../') } 12 | ], 13 | serverMiddleware: { 14 | '/api/echo': '~/api/echo', 15 | '/api/cookie': '~/api/cookie' 16 | }, 17 | axios: { 18 | prefix: '/api', 19 | proxy: true, 20 | credentials: true, 21 | debug: true, 22 | retry: true 23 | }, 24 | plugins: ['~/plugins/axios'] 25 | } 26 | -------------------------------------------------------------------------------- /test/fixture/pages/cancelToken.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 36 | -------------------------------------------------------------------------------- /docs/content/en/migration.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Migration guides' 3 | description: 'Migrate with confidence from one major version to another with our migrations guides.' 4 | position: 7 5 | category: 'Migration' 6 | --- 7 | 8 | ### From 4.x to 5.x 9 | 10 | **BaseURL options and handling have been completely rewritten.** 11 | 12 | Please refer to the latest docs. 13 | 14 | **Default prefix is now `/` instead of `/api`.** 15 | 16 | You have to explicitly add `/api/` in all requests. 17 | 18 | **`credentials` is now disabled by default.** 19 | 20 | For using old defaults: 21 | 22 | ```js 23 | { 24 | axios: { 25 | prefix: '/api', 26 | credentials: true 27 | } 28 | } 29 | ``` 30 | 31 | **Default error interceptor removed** 32 | 33 | **All lifecycle functions removed** 34 | 35 | You can now easily use a plugin to extend axios and add your custom logic there. 36 | 37 | Please see [Extending Axios](https://axios.nuxtjs.org/extend) section in docs. 38 | -------------------------------------------------------------------------------- /test/fixture/pages/cookie.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 36 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | ci: 13 | runs-on: ${{ matrix.os }} 14 | 15 | strategy: 16 | matrix: 17 | os: [ubuntu-latest] 18 | node: [12] 19 | 20 | steps: 21 | - uses: actions/setup-node@v2 22 | with: 23 | node-version: ${{ matrix.node }} 24 | 25 | - name: checkout 26 | uses: actions/checkout@master 27 | 28 | - name: cache node_modules 29 | uses: actions/cache@v2 30 | with: 31 | path: node_modules 32 | key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }} 33 | 34 | - name: Install dependencies 35 | if: steps.cache.outputs.cache-hit != 'true' 36 | run: yarn 37 | 38 | - name: Lint 39 | run: yarn lint 40 | 41 | - name: Test 42 | run: yarn jest 43 | 44 | - name: Coverage 45 | uses: codecov/codecov-action@v2 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Nuxt Community 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nuxtjs/axios", 3 | "version": "5.13.6", 4 | "description": "Secure and easy Axios integration with Nuxt.js", 5 | "repository": "nuxt-community/axios-module", 6 | "license": "MIT", 7 | "contributors": [ 8 | "Pooya Parsa " 9 | ], 10 | "main": "lib/module.js", 11 | "types": "types/index.d.ts", 12 | "files": [ 13 | "lib", 14 | "types/*.d.ts" 15 | ], 16 | "scripts": { 17 | "dev": "nuxt test/fixture", 18 | "lint": "eslint lib test", 19 | "release": "yarn test && standard-version && git push --follow-tags && npm publish", 20 | "test": "yarn lint && jest" 21 | }, 22 | "dependencies": { 23 | "@nuxtjs/proxy": "^2.1.0", 24 | "axios": "^0.25.0", 25 | "axios-retry": "^3.2.4", 26 | "consola": "^2.15.3", 27 | "defu": "^5.0.1" 28 | }, 29 | "devDependencies": { 30 | "@babel/core": "latest", 31 | "@babel/preset-env": "latest", 32 | "@nuxtjs/eslint-config": "latest", 33 | "babel-eslint": "latest", 34 | "babel-jest": "latest", 35 | "codecov": "latest", 36 | "eslint": "latest", 37 | "jest": "latest", 38 | "nuxt-edge": "latest", 39 | "standard-version": "latest" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/fixture/pages/ssr.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 44 | -------------------------------------------------------------------------------- /docs/content/en/extend.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Extending axios' 3 | description: 'Learn how to extend the axios module for Nuxt' 4 | position: 5 5 | category: 'API' 6 | --- 7 | 8 | ## Adding interceptors 9 | 10 | If you need to customize axios by registering interceptors and changing global config, you have to create a nuxt plugin. 11 | 12 | ```js{}[nuxt.config.js] 13 | export default { 14 | plugins: [ 15 | '~/plugins/axios' 16 | ] 17 | } 18 | ``` 19 | 20 | ```js{}[plugins/axios.js] 21 | export default function ({ $axios, redirect }) { 22 | $axios.onRequest(config => { 23 | console.log('Making request to ' + config.url) 24 | }) 25 | 26 | $axios.onError(error => { 27 | const code = parseInt(error.response && error.response.status) 28 | if (code === 400) { 29 | redirect('/400') 30 | } 31 | }) 32 | } 33 | ``` 34 | 35 | 36 | 37 | Learn more about [$axios's helpers](/helpers). 38 | 39 | 40 | 41 | 42 | ## New axios instance 43 | 44 | If you need to create your own axios instance which based on `$axios` defaults, you can use the `create` method. 45 | 46 | ```js{}[plugins/api.js] 47 | export default function ({ $axios }, inject) { 48 | // Create a custom axios instance 49 | const api = $axios.create({ 50 | headers: { 51 | common: { 52 | Accept: 'text/plain, */*' 53 | } 54 | } 55 | }) 56 | 57 | // Set baseURL to something different 58 | api.setBaseURL('https://my_api.com') 59 | 60 | // Inject to context as $api 61 | inject('api', api) 62 | } 63 | ``` 64 | 65 | Learn about [$axios's helpers](/helpers). 66 | -------------------------------------------------------------------------------- /docs/content/en/setup.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Setup' 3 | description: '' 4 | position: 2 5 | category: 'Getting started' 6 | --- 7 | 8 | 9 | ## Install 10 | 11 | Add `@nuxtjs/axios` dependency to your project: 12 | 13 | 14 | 15 | 16 | ```bash 17 | yarn add @nuxtjs/axios 18 | ``` 19 | 20 | 21 | 22 | 23 | ```bash 24 | npm install @nuxtjs/axios 25 | ``` 26 | 27 | 28 | 29 | 30 | Then add it to the `modules` section in your `nuxt.config.js`: 31 | 32 | ```js{}[nuxt.config.js] 33 | export default { 34 | modules: ['@nuxtjs/axios'] 35 | } 36 | ``` 37 | 38 | 39 | 40 | That's it! You can now use [$axios](/usage) in your Nuxt app ✨ 41 | 42 | 43 | 44 | ## Configure 45 | 46 | Add an `axios` object to your `nuxt.config.js` to configure global options which will be applied to all requests: 47 | 48 | ```js{}[nuxt.config.js] 49 | export default { 50 | modules: [ 51 | '@nuxtjs/axios', 52 | ], 53 | 54 | axios: { 55 | // proxy: true 56 | } 57 | } 58 | ``` 59 | 60 | Learn more about [axios's options](/options). 61 | 62 | ## TypeScript 63 | 64 | Add the types to your "types" array in `tsconfig.json` after the `@nuxt/types` (Nuxt 2.9.0+) or `@nuxt/vue-app` entry 65 | 66 | ```json{}[tsconfig.json] 67 | { 68 | "compilerOptions": { 69 | "types": [ 70 | "@nuxt/types", 71 | "@nuxtjs/axios" 72 | ] 73 | } 74 | } 75 | ``` 76 | > **Why?** 77 | > 78 | > Because of the way Nuxt works the `$axios` property on the context has to be merged into the Nuxt `Context` interface via [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html). Adding `@nuxtjs/axios` to your types will import the types from the package and make typescript aware of the additions to the `Context` interface. 79 | -------------------------------------------------------------------------------- /docs/content/en/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Introduction' 3 | description: 'The Axios module for Nuxt' 4 | position: 1 5 | category: '' 6 | menuTitle: 'Introduction' 7 | features: 8 | - Automatically set base URL for client & server side 9 | - Exposes `setToken` function to `$axios` so we can easily and globally set authentication tokens 10 | - Automatically enables `withCredentials` when requesting to base URL 11 | - Proxy request headers in SSR 12 | - Fetch Style requests 13 | - Integrated with Nuxt progress bar 14 | - Integrated with Proxy Module 15 | - Auto retry requests with axios-retry 16 | --- 17 | 18 | 19 | 20 | Axios module supports Nuxt 2. Nuxt 3 users can use the new isomorphic [useFetch](https://v3.nuxtjs.org/getting-started/data-fetching/) ([migration guide](https://nuxt.com/docs/migration/component-options/#isomorphic-fetch)). 21 | 22 | 23 | 24 | Nuxt Axios 25 | Nuxt Axios 26 | 27 | Secure and easy [Axios](https://github.com/axios/axios) integration for [Nuxt](https://nuxtjs.org). 28 | 29 | ## Features 30 | 31 | 32 | 33 |

Enjoy light and dark mode: 

34 | 35 | ## Logo 36 | 37 | Axios does not have an official logo yet, we decided to use the actual proposal submitted here: https://github.com/axios/axios/issues/2130 38 | 39 | ## Links 40 | 41 | * [GitHub](https://github.com/nuxt-community/axios-module) 42 | * [Release Notes](/releases) 43 | * [Migration Guide](/migration) 44 | 45 | 46 | 47 | To get started head to [Setup](/setup) section. 48 | 49 | 50 | 51 | ## Online courses 52 | 53 | 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![@nuxtjs/axios](https://axios.nuxtjs.org/preview.png)](https://axios.nuxtjs.org) 2 | 3 | # @nuxtjs/axios 4 | 5 | [![npm version][npm-version-src]][npm-version-href] 6 | [![npm downloads][npm-downloads-src]][npm-downloads-href] 7 | [![Github Actions CI][github-actions-ci-src]][github-actions-ci-href] 8 | [![Codecov][codecov-src]][codecov-href] 9 | [![License][license-src]][license-href] 10 | 11 | > Secure and easy [Axios](https://github.com/axios/axios) integration for [Nuxt 2](https://nuxt.com). 12 | 13 | - [✨  Release Notes](https://axios.nuxtjs.org/releases) 14 | - [📖  Documentation](https://axios.nuxtjs.org) 15 | 16 | ## Features 17 | 18 | - Automatically set base URL for client & server side 19 | - Exposes `setToken` function to `$axios` so we can easily and globally set authentication tokens 20 | - Automatically enables `withCredentials` when requesting to base URL 21 | - Proxy request headers in SSR 22 | - Fetch Style requests 23 | - Integrated with Nuxt progress bar 24 | - Integrated with Proxy Module 25 | - Auto retry requests with axios-retry 26 | 27 | [📖  Read more](https://axios.nuxtjs.org) 28 | 29 | ## Contributing 30 | 31 | 1. Clone this repository 32 | 2. Install dependencies using `yarn install` or `npm install` 33 | 3. Start development server using `npm run dev` 34 | 35 | ## 📑 License 36 | 37 | [MIT License](./LICENSE) 38 | 39 | Copyright (c) Nuxt Community 40 | 41 | 42 | 43 | [npm-version-src]: https://flat.badgen.net/npm/v/@nuxtjs/axios 44 | [npm-version-href]: https://npmjs.com/package/@nuxtjs/axios 45 | 46 | [npm-downloads-src]: https://flat.badgen.net/npm/dm/@nuxtjs/axios 47 | [npm-downloads-href]: https://npmjs.com/package/@nuxtjs/axios 48 | 49 | [github-actions-ci-src]: https://github.com/nuxt-community/axios-module/workflows/ci/badge.svg 50 | [github-actions-ci-href]: https://github.com/nuxt-community/axios-module/actions?query=workflow%3Aci 51 | 52 | [codecov-src]: https://flat.badgen.net/codecov/c/github/nuxt-community/axios-module 53 | [codecov-href]: https://codecov.io/gh/nuxt-community/axios-module 54 | 55 | [license-src]: https://img.shields.io/npm/l/@nuxtjs/axios.svg 56 | [license-href]: https://npmjs.com/package/@nuxtjs/axios 57 | -------------------------------------------------------------------------------- /docs/content/en/usage.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Usage' 3 | description: '' 4 | position: 3 5 | category: 'Getting started' 6 | --- 7 | 8 | 9 | ## Component 10 | 11 | **`asyncData`** 12 | 13 | ```js 14 | async asyncData({ $axios }) { 15 | const ip = await $axios.$get('http://icanhazip.com') 16 | return { ip } 17 | } 18 | ``` 19 | 20 | **`methods`/`created`/`mounted`/etc** 21 | 22 | ```js 23 | methods: { 24 | async fetchSomething() { 25 | const ip = await this.$axios.$get('http://icanhazip.com') 26 | this.ip = ip 27 | } 28 | } 29 | ``` 30 | 31 | ## Store Actions 32 | 33 | ```js 34 | // In store 35 | { 36 | actions: { 37 | async getIP ({ commit }) { 38 | const ip = await this.$axios.$get('http://icanhazip.com') 39 | commit('SET_IP', ip) 40 | } 41 | } 42 | } 43 | ``` 44 | 45 | ## `$` Shortcuts 46 | 47 | Axios plugin also supports shortcuts with `$` prefixed methods to directly get data: 48 | 49 | ```js 50 | // Normal usage with axios 51 | let data = (await $axios.get('...')).data 52 | 53 | // Fetch Style 54 | let data = await $axios.$get('...') 55 | ``` 56 | 57 | ## Cancel token 58 | 59 | You can cancel a request using a _cancel token_. 60 | 61 | > The axios cancel token API is based on the withdrawn [cancelable promises proposal](https://github.com/tc39/proposal-cancelable-promises). 62 | 63 | You can create a cancel token using the `CancelToken.source` factory as shown below: 64 | 65 | ```js 66 | const source = this.$axios.CancelToken.source() 67 | 68 | this.$axios.$get('/user/12345', { 69 | cancelToken: source.token 70 | }).catch(error => { 71 | if (this.$axios.isCancel(error)) { 72 | console.log('Request canceled', error) 73 | } else { 74 | // handle error 75 | } 76 | }) 77 | 78 | this.$axios.$post('/user/12345', { 79 | name: 'new name' 80 | }, { 81 | cancelToken: source.token 82 | }) 83 | 84 | // cancel the request (the message parameter is optional) 85 | source.cancel('Operation canceled by the user.') 86 | ``` 87 | 88 | You can also create a cancel token by passing an executor function to the `CancelToken` constructor: 89 | 90 | ```js 91 | const { CancelToken } = this.$axios 92 | let cancel 93 | 94 | this.$axios.$get('/user/12345', { 95 | cancelToken: new CancelToken(c => { 96 | // An executor function receives a cancel function as a parameter 97 | cancel = c 98 | }), 99 | }) 100 | 101 | // cancel the request 102 | cancel() 103 | ``` 104 | 105 | > Note: you can cancel several requests with the same cancel token. 106 | -------------------------------------------------------------------------------- /docs/components/global/PromoteBlock.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 19 | 20 | 107 | -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { AxiosError, AxiosRequestConfig, AxiosResponse, AxiosStatic } from 'axios' 2 | import { IAxiosRetryConfig } from 'axios-retry' 3 | import Vue from 'vue' 4 | import './vuex' 5 | 6 | interface NuxtAxiosInstance extends AxiosStatic { 7 | $request(config: AxiosRequestConfig): Promise 8 | $get(url: string, config?: AxiosRequestConfig): Promise 9 | $delete(url: string, config?: AxiosRequestConfig): Promise 10 | $head(url: string, config?: AxiosRequestConfig): Promise 11 | $options(url: string, config?: AxiosRequestConfig): Promise 12 | $post(url: string, data?: any, config?: AxiosRequestConfig): Promise 13 | $put(url: string, data?: any, config?: AxiosRequestConfig): Promise 14 | $patch(url: string, data?: any, config?: AxiosRequestConfig): Promise 15 | 16 | setBaseURL(baseURL: string): void 17 | setHeader(name: string, value?: string | false, scopes?: string | string[]): void 18 | setToken(token: string | false, type?: string, scopes?: string | string[]): void 19 | 20 | onRequest(callback: (config: AxiosRequestConfig) => void | AxiosRequestConfig | Promise): void 21 | onResponse(callback: (response: AxiosResponse) => void | AxiosResponse | Promise> ): void 22 | onError(callback: (error: AxiosError) => any): void 23 | onRequestError(callback: (error: AxiosError) => any): void 24 | onResponseError(callback: (error: AxiosError) => any): void 25 | 26 | create(options?: AxiosRequestConfig): NuxtAxiosInstance 27 | } 28 | 29 | interface AxiosOptions { 30 | baseURL?: string, 31 | browserBaseURL?: string, 32 | credentials?: boolean, 33 | debug?: boolean, 34 | host?: string, 35 | prefix?: string, 36 | progress?: boolean, 37 | proxyHeaders?: boolean, 38 | proxyHeadersIgnore?: string[], 39 | proxy?: boolean, 40 | port?: string | number, 41 | retry?: boolean | IAxiosRetryConfig, 42 | https?: boolean, 43 | headers?: { 44 | common?: Record, 45 | delete?: Record, 46 | get?: Record, 47 | head?: Record, 48 | post?: Record, 49 | put?: Record, 50 | patch?: Record, 51 | }, 52 | } 53 | 54 | declare module 'axios' { 55 | interface AxiosRequestConfig { 56 | progress?: boolean; 57 | } 58 | } 59 | 60 | declare module '@nuxt/vue-app' { 61 | interface Context { 62 | $axios: NuxtAxiosInstance 63 | } 64 | interface NuxtAppOptions { 65 | $axios: NuxtAxiosInstance 66 | } 67 | } 68 | 69 | // Nuxt 2.9+ 70 | declare module '@nuxt/types' { 71 | interface Context { 72 | $axios: NuxtAxiosInstance 73 | } 74 | 75 | interface NuxtAppOptions { 76 | $axios: NuxtAxiosInstance 77 | } 78 | 79 | interface Configuration { 80 | axios?: AxiosOptions 81 | } 82 | } 83 | 84 | declare module 'vue/types/vue' { 85 | interface Vue { 86 | $axios: NuxtAxiosInstance 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /lib/module.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const consola = require('consola') 3 | const defu = require('defu') 4 | 5 | const logger = consola.withScope('nuxt:axios') 6 | 7 | function axiosModule (_moduleOptions) { 8 | const { nuxt } = this 9 | 10 | // Combine options 11 | const moduleOptions = { 12 | ...nuxt.options.axios, 13 | ..._moduleOptions, 14 | ...(nuxt.options.runtimeConfig && nuxt.options.runtimeConfig.axios) 15 | } 16 | 17 | // Default port 18 | const defaultPort = 19 | process.env.API_PORT || 20 | moduleOptions.port || 21 | process.env.PORT || 22 | process.env.npm_package_config_nuxt_port || 23 | (this.options.server && this.options.server.port) || 24 | 3000 25 | 26 | // Default host 27 | let defaultHost = 28 | process.env.API_HOST || 29 | moduleOptions.host || 30 | process.env.HOST || 31 | process.env.npm_package_config_nuxt_host || 32 | (this.options.server && this.options.server.host) || 33 | 'localhost' 34 | 35 | /* istanbul ignore if */ 36 | if (defaultHost === '0.0.0.0') { 37 | defaultHost = 'localhost' 38 | } 39 | 40 | // Transpile defu (IE11) 41 | if (nuxt.options.build.transpile /* nuxt 1 */) { 42 | nuxt.options.build.transpile.push(({ isClient }) => isClient && 'defu') 43 | } 44 | 45 | // Default prefix 46 | const prefix = process.env.API_PREFIX || moduleOptions.prefix || '/' 47 | 48 | // HTTPS 49 | const https = Boolean(this.options.server && this.options.server.https) 50 | 51 | // Headers 52 | const headers = { 53 | common: { 54 | Accept: 'application/json, text/plain, */*' 55 | }, 56 | delete: {}, 57 | get: {}, 58 | head: {}, 59 | post: {}, 60 | put: {}, 61 | patch: {} 62 | } 63 | 64 | // Support baseUrl alternative 65 | if (moduleOptions.baseUrl) { 66 | moduleOptions.baseURL = moduleOptions.baseUrl 67 | delete moduleOptions.baseUrl 68 | } 69 | if (moduleOptions.browserBaseUrl) { 70 | moduleOptions.browserBaseURL = moduleOptions.browserBaseUrl 71 | delete moduleOptions.browserBaseUrl 72 | } 73 | 74 | // Apply defaults 75 | const options = defu(moduleOptions, { 76 | baseURL: `http://${defaultHost}:${defaultPort}${prefix}`, 77 | browserBaseURL: undefined, 78 | credentials: false, 79 | debug: false, 80 | progress: true, 81 | proxyHeaders: true, 82 | proxyHeadersIgnore: [ 83 | 'accept', 84 | 'cf-connecting-ip', 85 | 'cf-ray', 86 | 'content-length', 87 | 'content-md5', 88 | 'content-type', 89 | 'host', 90 | 'x-forwarded-host', 91 | 'x-forwarded-port', 92 | 'x-forwarded-proto' 93 | ], 94 | proxy: false, 95 | retry: false, 96 | https, 97 | headers 98 | }) 99 | 100 | // ENV overrides 101 | 102 | /* istanbul ignore if */ 103 | if (process.env.API_URL) { 104 | options.baseURL = process.env.API_URL 105 | } 106 | 107 | /* istanbul ignore if */ 108 | if (process.env.API_URL_BROWSER) { 109 | options.browserBaseURL = process.env.API_URL_BROWSER 110 | } 111 | 112 | // Default browserBaseURL 113 | if (typeof options.browserBaseURL === 'undefined') { 114 | options.browserBaseURL = options.proxy ? prefix : options.baseURL 115 | } 116 | 117 | // Normalize options 118 | if (options.retry === true) { 119 | options.retry = {} 120 | } 121 | 122 | // Convert http:// to https:// if https option is on 123 | if (options.https === true) { 124 | const https = s => s.replace('http://', 'https://') 125 | options.baseURL = https(options.baseURL) 126 | options.browserBaseURL = https(options.browserBaseURL) 127 | } 128 | 129 | // globalName 130 | options.globalName = this.nuxt.options.globalName || 'nuxt' 131 | 132 | // Register plugin 133 | this.addPlugin({ 134 | src: path.resolve(__dirname, 'plugin.js'), 135 | fileName: 'axios.js', 136 | options 137 | }) 138 | 139 | // Proxy integration 140 | if (options.proxy) { 141 | this.requireModule([ 142 | '@nuxtjs/proxy', 143 | typeof options.proxy === 'object' ? options.proxy : {} 144 | ]) 145 | } 146 | 147 | // Set _AXIOS_BASE_URL_ for dynamic SSR baseURL 148 | process.env._AXIOS_BASE_URL_ = options.baseURL 149 | 150 | logger.debug(`baseURL: ${options.baseURL}`) 151 | logger.debug(`browserBaseURL: ${options.browserBaseURL}`) 152 | } 153 | 154 | module.exports = axiosModule 155 | module.exports.meta = require('../package.json') 156 | -------------------------------------------------------------------------------- /docs/content/en/helpers.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Helpers' 3 | description: 'Discover the helpers to supercharge your Axios instance' 4 | position: 6 5 | category: 'API' 6 | --- 7 | 8 | Discover the helpers to supercharge your axios instance. 9 | 10 | ## Interceptors 11 | 12 | Axios plugin provides helpers to register axios interceptors easier and faster. 13 | 14 | - `onRequest(config)` 15 | - `onResponse(response)` 16 | - `onError(err)` 17 | - `onRequestError(err)` 18 | - `onResponseError(err)` 19 | 20 | These functions don't have to return anything by default. 21 | 22 | Example: (`plugins/axios.js`) 23 | 24 | ```js 25 | export default function ({ $axios, redirect }) { 26 | $axios.onError(error => { 27 | if(error.response.status === 500) { 28 | redirect('/sorry') 29 | } 30 | }) 31 | } 32 | ``` 33 | 34 | When intercepting an error, you can return a resolved promise to prevent the error from propagating. 35 | 36 | Example: (`plugins/axios.js`) 37 | 38 | ```js 39 | export default function ({ $axios, error: nuxtError }) { 40 | $axios.onError(error => { 41 | nuxtError({ 42 | statusCode: error.response.status, 43 | message: error.message, 44 | }); 45 | return Promise.resolve(false); 46 | }) 47 | } 48 | ``` 49 | 50 | 51 | 52 | Learn more about [extending axios](/extend) 53 | 54 | 55 | 56 | ## `setBaseURL` 57 | 58 | - Signature: `setBaseURL(baseURL)` 59 | 60 | Axios instance has an additional helper to easily change baseURL. 61 | 62 | Use this when you need a dynamic runtime url. Otherwise use config and environment variables. 63 | 64 | **NOTE:** When calling `setBaseURL`, it globally set's baseURL for session (one SSR request or browser tab) so it is adviced to only call it in application entrypoint with a plugin not in components. Subeffects can cause breaking other requests! 65 | 66 | Parameters: 67 | 68 | * **baseURL**: Base URL which is used and prepended to make requests in server side. 69 | 70 | ```js 71 | // Set baseURL (both client and server) 72 | this.$axios.setBaseURL('http://api.example.com') 73 | 74 | // Change URL only for client 75 | if (process.client) { 76 | this.$axios.setBaseURL('http://api.example.com') 77 | } 78 | 79 | // Change URL only for server 80 | if (process.server) { 81 | this.$axios.setBaseURL('http://api.example.com') 82 | } 83 | ``` 84 | 85 | ## `setHeader` 86 | 87 | - Signature: `setHeader(name, value, scopes='common')` 88 | 89 | Axios instance has a helper to easily set any header. 90 | 91 | Parameters: 92 | 93 | * **name**: Name of the header 94 | * **value**: Value of the header 95 | * **scopes**: Send only on specific type of requests. Defaults 96 | * Type: _Array_ or _String_ 97 | * Defaults to `common` meaning all types of requests 98 | * Can be `get`, `post`, `delete`, ... 99 | 100 | ```js 101 | // Adds header: `Authorization: 123` to all requests 102 | this.$axios.setHeader('Authorization', '123') 103 | 104 | // Overrides `Authorization` header with new value 105 | this.$axios.setHeader('Authorization', '456') 106 | 107 | // Adds header: `Content-Type: application/x-www-form-urlencoded` to only post requests 108 | this.$axios.setHeader('Content-Type', 'application/x-www-form-urlencoded', [ 109 | 'post' 110 | ]) 111 | 112 | // Removes default Content-Type header from `post` scope 113 | this.$axios.setHeader('Content-Type', false, ['post']) 114 | ``` 115 | 116 | ## `setToken` 117 | 118 | - Signature: `setToken(token, type, scopes='common')` 119 | 120 | Axios instance has an additional helper to easily set global authentication header. 121 | 122 | Parameters: 123 | 124 | * **token**: Authorization token 125 | * **type**: Authorization token prefix(Usually `Bearer`). 126 | * **scopes**: Send only on specific type of requests. Defaults 127 | * Type: _Array_ or _String_ 128 | * Defaults to `common` meaning all types of requests 129 | * Can be `get`, `post`, `delete`, ... 130 | 131 | ```js 132 | // Adds header: `Authorization: 123` to all requests 133 | this.$axios.setToken('123') 134 | 135 | // Overrides `Authorization` header with new value 136 | this.$axios.setToken('456') 137 | 138 | // Adds header: `Authorization: Bearer 123` to all requests 139 | this.$axios.setToken('123', 'Bearer') 140 | 141 | // Adds header: `Authorization: Bearer 123` to only post and delete requests 142 | this.$axios.setToken('123', 'Bearer', ['post', 'delete']) 143 | 144 | // Removes default Authorization header from `common` scope (all requests) 145 | this.$axios.setToken(false) 146 | ``` 147 | -------------------------------------------------------------------------------- /test/axios.test.js: -------------------------------------------------------------------------------- 1 | jest.setTimeout(60000) 2 | 3 | const { Nuxt, Builder } = require('nuxt-edge') 4 | const axios = require('axios') 5 | 6 | const config = require('./fixture/nuxt.config') 7 | 8 | let nuxt, addTemplate 9 | 10 | const url = path => `http://localhost:3000${path}` 11 | 12 | const setupNuxt = async (config) => { 13 | nuxt = new Nuxt(config) 14 | 15 | // Spy addTemplate 16 | addTemplate = nuxt.moduleContainer.addTemplate = jest.fn( 17 | nuxt.moduleContainer.addTemplate 18 | ) 19 | 20 | const build = new Builder(nuxt) 21 | 22 | await build.validatePages() 23 | await build.generateRoutesAndFiles() 24 | await nuxt.listen(3000) 25 | } 26 | 27 | const testSuite = () => { 28 | test('baseURL', () => { 29 | expect(addTemplate).toBeDefined() 30 | const call = addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js')) 31 | const options = call[0].options 32 | const proto = options.https ? 'https' : 'http' 33 | expect(options.baseURL.toString()).toBe(`${proto}://localhost:3000/api`) 34 | expect(options.browserBaseURL.toString()).toBe('/api') 35 | }) 36 | 37 | test('asyncData', async () => { 38 | const html = (await axios.get(url('/asyncData'))).data 39 | expect(html).toContain('foo/bar') 40 | }) 41 | 42 | test('mounted', async () => { 43 | const window = await nuxt.renderAndGetWindow(url('/mounted')) 44 | window.onNuxtReady(() => { 45 | const html = window.document.body.innerHTML 46 | expect(html).toContain('foo/bar') 47 | }) 48 | }) 49 | 50 | test('init', async () => { 51 | const window = await nuxt.renderAndGetWindow(url('/mounted')) 52 | window.onNuxtReady(() => { 53 | const $axios = window.$nuxt.$axios 54 | expect($axios.defaults.xsrfHeaderName).toBe('X-CSRF-TOKEN') 55 | }) 56 | }) 57 | 58 | test('createCopy', async () => { 59 | const window = await nuxt.renderAndGetWindow(url('/mounted')) 60 | window.onNuxtReady(() => { 61 | const $axios = window.$nuxt.$axios 62 | const newInstance = $axios.create() 63 | expect(newInstance.defaults.xsrfHeaderName).toBe('X-CSRF-TOKEN') 64 | }) 65 | }) 66 | 67 | test('ssr', async () => { 68 | const makeReq = login => axios 69 | .get(url('/ssr' + (login ? '?login' : ''))) 70 | .then(r => r.data) 71 | .then(h => /session-[0-9]+/.exec(h)) 72 | .then(m => (m && m[0] ? m[0] : null)) 73 | 74 | const a = await makeReq() 75 | const b = await makeReq(true) 76 | const c = await makeReq() 77 | const d = await makeReq(true) 78 | 79 | expect(a).toBeNull() 80 | expect(b).not.toBeNull() 81 | expect(c).toBeNull() // Important! 82 | expect(d).not.toBeNull() 83 | expect(b).not.toBe(d) 84 | }) 85 | 86 | test('ssr no brotli', async () => { 87 | const makeReq = login => axios 88 | .get(url('/ssr' + (login ? '?login' : ''))) 89 | .then(r => r.data) 90 | .then(h => /encoding-\$(.*)\$/.exec(h)) 91 | .then(m => (m && m[1] ? m[1] : null)) 92 | 93 | const result = await makeReq() 94 | 95 | expect(result).toBe('gzip, deflate') 96 | }) 97 | } 98 | 99 | describe('module', () => { 100 | beforeAll(async () => { 101 | nuxt = new Nuxt(config) 102 | 103 | // Spy addTemplate 104 | addTemplate = nuxt.moduleContainer.addTemplate = jest.fn( 105 | nuxt.moduleContainer.addTemplate 106 | ) 107 | 108 | await new Builder(nuxt).build() 109 | await nuxt.listen(3000) 110 | }) 111 | 112 | afterAll(async () => { 113 | await nuxt.close() 114 | }) 115 | 116 | testSuite() 117 | }) 118 | 119 | describe('other options', () => { 120 | beforeAll(async () => { 121 | config.axios = { 122 | prefix: '/api', 123 | proxy: {}, 124 | credentials: true, 125 | https: true, 126 | retry: false 127 | } 128 | 129 | await setupNuxt(config) 130 | }) 131 | 132 | afterAll(async () => { 133 | await nuxt.close() 134 | }) 135 | 136 | testSuite() 137 | }) 138 | 139 | describe('browserBaseURL', () => { 140 | beforeAll(async () => { 141 | config.axios = { 142 | browserBaseURL: '/api' 143 | } 144 | 145 | await setupNuxt(config) 146 | }) 147 | 148 | afterAll(async () => { 149 | await nuxt.close() 150 | }) 151 | 152 | test('custom', () => { 153 | expect(addTemplate).toBeDefined() 154 | const call = addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js')) 155 | const options = call[0].options 156 | expect(options.baseURL.toString()).toBe('http://localhost:3000/') 157 | expect(options.browserBaseURL.toString()).toBe('/api') 158 | }) 159 | }) 160 | 161 | describe('empty config', () => { 162 | beforeAll(async () => { 163 | config.axios = {} 164 | 165 | await setupNuxt(config) 166 | }) 167 | 168 | afterAll(async () => { 169 | await nuxt.close() 170 | }) 171 | 172 | test('preset baseURL and browserBaseURL', () => { 173 | expect(addTemplate).toBeDefined() 174 | const call = addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js')) 175 | const options = call[0].options 176 | expect(options.baseURL.toString()).toBe('http://localhost:3000/') 177 | expect(options.browserBaseURL.toString()).toBe('http://localhost:3000/') 178 | }) 179 | }) 180 | -------------------------------------------------------------------------------- /docs/static/logo-dark.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /docs/static/logo-light.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /docs/content/en/options.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Options' 3 | description: 'Discover the available options to configure Axios in Nuxt' 4 | position: 4 5 | category: 'Getting started' 6 | --- 7 | 8 | You can pass different options using the `axios` property in your `nuxt.config.js`: 9 | 10 | ```js{}[nuxt.config.js] 11 | export default { 12 | axios: { 13 | // Axios options here 14 | } 15 | } 16 | ``` 17 | 18 | ## Runtime Config 19 | 20 | The use of [runtime config](https://nuxtjs.org/guide/runtime-config) is mandatory in case of using environment variables in production, otherwise, the values will be hard coded during build and won't change. 21 | 22 | Supported options: 23 | 24 | - `baseURL` 25 | - `browserBaseURL` 26 | 27 | **nuxt.config.js** 28 | 29 | ```js 30 | export default { 31 | modules: [ 32 | '@nuxtjs/axios' 33 | ], 34 | 35 | axios: { 36 | baseURL: 'http://localhost:4000', // Used as fallback if no runtime config is provided 37 | }, 38 | 39 | publicRuntimeConfig: { 40 | axios: { 41 | browserBaseURL: process.env.BROWSER_BASE_URL 42 | } 43 | }, 44 | 45 | privateRuntimeConfig: { 46 | axios: { 47 | baseURL: process.env.BASE_URL 48 | } 49 | }, 50 | } 51 | ``` 52 | 53 | ## `prefix`, `host` and `port` 54 | 55 | These options are used for the default values of `baseURL` and `browserBaseURL`. 56 | 57 | They can be customized with `API_PREFIX`, `API_HOST` (or `HOST`) and `API_PORT` (or `PORT`) environment variables. 58 | 59 | Default value of `prefix` is `/`. 60 | 61 | ## `baseURL` 62 | 63 | * Default: `http://[HOST]:[PORT][PREFIX]` 64 | 65 | Defines the base URL which is used and prepended to make server side requests. 66 | 67 | Environment variable `API_URL` can be used to **override** `baseURL`. 68 | 69 | **WARNING:** `baseURL` and `proxy` cannot be used at the same time, so when the `proxy` option is in use, you need to define `prefix` instead of `baseURL`. 70 | 71 | ## `browserBaseURL` 72 | 73 | * Default: `baseURL` 74 | 75 | Defines the base URL which is used and prepended to make client side requests. 76 | 77 | The environment variable `API_URL_BROWSER` can be used to **override** `browserBaseURL`. 78 | 79 | **WARNING:** when the `proxy` option is enabled the default for `browserBaseURL` becomes `prefix` instead of `baseURL`. 80 | 81 | ## `https` 82 | 83 | * Default: `false` 84 | 85 | If set to `true`, `http://` in both `baseURL` and `browserBaseURL` will be changed into `https://`. 86 | 87 | ## `progress` 88 | 89 | * Default: `true` 90 | 91 | This option shows a loading bar while making requests integrating Nuxt.js progress bar (see "loading" options in config.nuxt.js). This is active only in the browser, and when loading bar is enabled and available. 92 | 93 | You can also disable the progress bar in specific requests using the `progress` option in an inline request configuration: 94 | 95 | ```js 96 | this.$axios.$get('URL', { progress: false }) 97 | ``` 98 | 99 | ## `proxy` 100 | 101 | * Default: `false` 102 | 103 | You can easily integrate Axios with [Proxy Module](https://github.com/nuxt-community/proxy-module). This is highly recommended to prevent CORS and production/deployment problems. 104 | 105 | **nuxt.config.js** 106 | 107 | ```js 108 | { 109 | modules: [ 110 | '@nuxtjs/axios' 111 | ], 112 | 113 | axios: { 114 | proxy: true // Can be also an object with default options 115 | }, 116 | 117 | proxy: { 118 | '/api/': 'http://api.example.com', 119 | '/api2/': 'http://api.another-website.com' 120 | } 121 | } 122 | ``` 123 | 124 | **Note:** It is not required to manually register `@nuxtjs/proxy` module, but it does need to be in your dependencies. 125 | 126 | **Note:** In the proxy module, `/api/` will be added to all requests to the API end point. If you need to remove it use the `pathRewrite` option: 127 | 128 | ```js 129 | proxy: { 130 | '/api/': { target: 'http://api.example.com', pathRewrite: {'^/api/': ''} } 131 | } 132 | ``` 133 | 134 | ## `retry` 135 | 136 | * Default: `false` 137 | 138 | Automatically intercept failed requests and retries them whenever posible using [axios-retry](https://github.com/softonic/axios-retry). 139 | 140 | By default, number of retries will be **3 times**, if `retry` value is set to `true`. You can change it by passing the option with an inline retries sub-option like this: 141 | 142 | ```js 143 | axios: { 144 | retry: { retries: 3 } 145 | } 146 | ``` 147 | 148 | ## `credentials` 149 | 150 | * Default: `false` 151 | 152 | Adds an interceptor that automatically sets `withCredentials` axios configuration when issuing a request to `baseURL` 153 | that needs to pass authentication headers to the backend. 154 | 155 | ## `debug` 156 | 157 | * Default: `false` 158 | 159 | Adds interceptors that logs axios request and responses. 160 | 161 | ## `proxyHeaders` 162 | 163 | * Default: `true` 164 | 165 | In SSR context, this options sets client requests headers as default headers for the axios requests. 166 | This is useful for making requests which need cookie based auth on server side. 167 | This also helps making consistent requests in both SSR and Client Side code. 168 | 169 | ## `proxyHeadersIgnore` 170 | 171 | * Default `['accept', 'host', 'x-forwarded-host', 'x-forwarded-port', 'x-forwarded-proto', 'cf-ray', 'cf-connecting-ip', 'content-length', 'content-md5', 'content-type']` 172 | 173 | This is useful and effective only when `proxyHeaders` is set to true. It removes unwanted requests headers to the API backend in SSR. 174 | 175 | Ignoring headers like `x-forwarded-host` is necessary to avoid confusing reverse proxies (like Nginx and CloudFlare) and avoid causing proxy loops. 176 | 177 | ## `headers` 178 | 179 | Headers added to all requests. If provided, will be merged with the defaults. 180 | 181 | ```js 182 | { 183 | common: { 184 | 'Accept': 'application/json, text/plain, */*' 185 | }, 186 | delete: {}, 187 | get: {}, 188 | head: {}, 189 | post: {}, 190 | put: {}, 191 | patch: {} 192 | } 193 | ``` 194 | 195 | - **NOTE:** Do NOT include any credentials or tokens here. They can be easily accessed. 196 | - **NOTE:** These headers take effect on ALL requests. Wherever possible, consider providing headers on specific requests instead. 197 | -------------------------------------------------------------------------------- /lib/plugin.js: -------------------------------------------------------------------------------- 1 | import Axios from 'axios' 2 | import defu from 'defu' 3 | <% if (options.retry) { %>import axiosRetry from 'axios-retry'<% } %> 4 | 5 | // Axios.prototype cannot be modified 6 | const axiosExtra = { 7 | setBaseURL (baseURL) { 8 | this.defaults.baseURL = baseURL 9 | }, 10 | setHeader (name, value, scopes = 'common') { 11 | for (const scope of Array.isArray(scopes) ? scopes : [ scopes ]) { 12 | if (!value) { 13 | delete this.defaults.headers[scope][name]; 14 | continue 15 | } 16 | this.defaults.headers[scope][name] = value 17 | } 18 | }, 19 | setToken (token, type, scopes = 'common') { 20 | const value = !token ? null : (type ? type + ' ' : '') + token 21 | this.setHeader('Authorization', value, scopes) 22 | }, 23 | onRequest(fn) { 24 | this.interceptors.request.use(config => fn(config) || config) 25 | }, 26 | onResponse(fn) { 27 | this.interceptors.response.use(response => fn(response) || response) 28 | }, 29 | onRequestError(fn) { 30 | this.interceptors.request.use(undefined, error => fn(error) || Promise.reject(error)) 31 | }, 32 | onResponseError(fn) { 33 | this.interceptors.response.use(undefined, error => fn(error) || Promise.reject(error)) 34 | }, 35 | onError(fn) { 36 | this.onRequestError(fn) 37 | this.onResponseError(fn) 38 | }, 39 | create(options) { 40 | return createAxiosInstance(defu(options, this.defaults)) 41 | } 42 | } 43 | 44 | // Request helpers ($get, $post, ...) 45 | for (const method of ['request', 'delete', 'get', 'head', 'options', 'post', 'put', 'patch']) { 46 | axiosExtra['$' + method] = function () { return this[method].apply(this, arguments).then(res => res && res.data) } 47 | } 48 | 49 | const extendAxiosInstance = axios => { 50 | for (const key in axiosExtra) { 51 | axios[key] = axiosExtra[key].bind(axios) 52 | } 53 | } 54 | 55 | const createAxiosInstance = axiosOptions => { 56 | // Create new axios instance 57 | const axios = Axios.create(axiosOptions) 58 | axios.CancelToken = Axios.CancelToken 59 | axios.isCancel = Axios.isCancel 60 | 61 | // Extend axios proto 62 | extendAxiosInstance(axios) 63 | 64 | // Intercept to apply default headers 65 | axios.onRequest((config) => { 66 | config.headers = { ...axios.defaults.headers.common, ...config.headers } 67 | }) 68 | 69 | // Setup interceptors 70 | <% if (options.debug) { %>setupDebugInterceptor(axios) <% } %> 71 | <% if (options.credentials) { %>setupCredentialsInterceptor(axios) <% } %> 72 | <% if (options.progress) { %>setupProgress(axios) <% } %> 73 | <% if (options.retry) { %>axiosRetry(axios, <%= serialize(options.retry) %>) <% } %> 74 | 75 | return axios 76 | } 77 | 78 | <% if (options.debug) { %> 79 | const log = (level, ...messages) => console[level]('[Axios]', ...messages) 80 | 81 | const setupDebugInterceptor = axios => { 82 | // request 83 | axios.onRequestError(error => { 84 | log('error', 'Request error:', error) 85 | }) 86 | 87 | // response 88 | axios.onResponseError(error => { 89 | log('error', 'Response error:', error) 90 | }) 91 | axios.onResponse(res => { 92 | log( 93 | 'info', 94 | '[' + (res.status + ' ' + res.statusText) + ']', 95 | '[' + res.config.method.toUpperCase() + ']', 96 | res.config.url) 97 | 98 | if (process.client) { 99 | console.log(res) 100 | } else { 101 | console.log(JSON.stringify(res.data, undefined, 2)) 102 | } 103 | 104 | return res 105 | }) 106 | }<% } %> 107 | 108 | <% if (options.credentials) { %> 109 | const setupCredentialsInterceptor = axios => { 110 | // Send credentials only to relative and API Backend requests 111 | axios.onRequest(config => { 112 | if (config.withCredentials === undefined) { 113 | if (!/^https?:\/\//i.test(config.url) || config.url.indexOf(config.baseURL) === 0) { 114 | config.withCredentials = true 115 | } 116 | } 117 | }) 118 | }<% } %> 119 | 120 | <% if (options.progress) { %> 121 | const setupProgress = (axios) => { 122 | if (process.server) { 123 | return 124 | } 125 | 126 | // A noop loading inteterface for when $nuxt is not yet ready 127 | const noopLoading = { 128 | finish: () => { }, 129 | start: () => { }, 130 | fail: () => { }, 131 | set: () => { } 132 | } 133 | 134 | const $loading = () => { 135 | const $nuxt = typeof window !== 'undefined' && window['$<%= options.globalName %>'] 136 | return ($nuxt && $nuxt.$loading && $nuxt.$loading.set) ? $nuxt.$loading : noopLoading 137 | } 138 | 139 | let currentRequests = 0 140 | 141 | axios.onRequest(config => { 142 | if (config && config.progress === false) { 143 | return 144 | } 145 | 146 | currentRequests++ 147 | }) 148 | 149 | axios.onResponse(response => { 150 | if (response && response.config && response.config.progress === false) { 151 | return 152 | } 153 | 154 | currentRequests-- 155 | if (currentRequests <= 0) { 156 | currentRequests = 0 157 | $loading().finish() 158 | } 159 | }) 160 | 161 | axios.onError(error => { 162 | if (error && error.config && error.config.progress === false) { 163 | return 164 | } 165 | 166 | currentRequests-- 167 | 168 | if (Axios.isCancel(error)) { 169 | if (currentRequests <= 0) { 170 | currentRequests = 0 171 | $loading().finish() 172 | } 173 | return 174 | } 175 | 176 | $loading().fail() 177 | $loading().finish() 178 | }) 179 | 180 | const onProgress = e => { 181 | if (!currentRequests || !e.total) { 182 | return 183 | } 184 | const progress = ((e.loaded * 100) / (e.total * currentRequests)) 185 | $loading().set(Math.min(100, progress)) 186 | } 187 | 188 | axios.defaults.onUploadProgress = onProgress 189 | axios.defaults.onDownloadProgress = onProgress 190 | }<% } %> 191 | 192 | export default (ctx, inject) => { 193 | // runtimeConfig 194 | const runtimeConfig = ctx.$config && ctx.$config.axios || {} 195 | // baseURL 196 | const baseURL = process.client 197 | ? (runtimeConfig.browserBaseURL || runtimeConfig.browserBaseUrl || runtimeConfig.baseURL || runtimeConfig.baseUrl || '<%= options.browserBaseURL || '' %>') 198 | : (runtimeConfig.baseURL || runtimeConfig.baseUrl || process.env._AXIOS_BASE_URL_ || '<%= options.baseURL || '' %>') 199 | 200 | // Create fresh objects for all default header scopes 201 | // Axios creates only one which is shared across SSR requests! 202 | // https://github.com/mzabriskie/axios/blob/master/lib/defaults.js 203 | const headers = <%= JSON.stringify(options.headers, null, 4) %> 204 | 205 | const axiosOptions = { 206 | baseURL, 207 | headers 208 | } 209 | 210 | <% if (options.proxyHeaders) { %> 211 | // Proxy SSR request headers headers 212 | if (process.server && ctx.req && ctx.req.headers) { 213 | const reqHeaders = { ...ctx.req.headers } 214 | for (const h of <%= serialize(options.proxyHeadersIgnore) %>) { 215 | delete reqHeaders[h] 216 | } 217 | axiosOptions.headers.common = { ...reqHeaders, ...axiosOptions.headers.common } 218 | } 219 | <% } %> 220 | 221 | if (process.server) { 222 | // Don't accept brotli encoding because Node can't parse it 223 | axiosOptions.headers.common['accept-encoding'] = 'gzip, deflate' 224 | } 225 | 226 | const axios = createAxiosInstance(axiosOptions) 227 | 228 | // Inject axios to the context as $axios 229 | ctx.$axios = axios 230 | inject('axios', axios) 231 | } 232 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ### [5.13.6](https://github.com/nuxt-community/axios-module/compare/v5.13.5...v5.13.6) (2021-06-02) 6 | 7 | 8 | ### Bug Fixes 9 | 10 | * setHeader function returns after the first scope element ([#507](https://github.com/nuxt-community/axios-module/issues/507)) ([cb5e29d](https://github.com/nuxt-community/axios-module/commit/cb5e29dc61a22c6b45b90c245552f1fa2cb5719b)) 11 | 12 | ### [5.13.5](https://github.com/nuxt-community/axios-module/compare/v5.13.4...v5.13.5) (2021-05-26) 13 | 14 | 15 | ### Bug Fixes 16 | 17 | * only transpile defu for client bundle (resolves [#501](https://github.com/nuxt-community/axios-module/issues/501)) ([ec2eb0a](https://github.com/nuxt-community/axios-module/commit/ec2eb0ae8642aaa3f3e51505f4ec86b699d09d90)) 18 | 19 | ### [5.13.4](https://github.com/nuxt-community/axios-module/compare/v5.13.3...v5.13.4) (2021-05-18) 20 | 21 | 22 | ### Bug Fixes 23 | 24 | * `build.transpile` guard for nuxt@1.x (fixes [#498](https://github.com/nuxt-community/axios-module/issues/498)) ([66d56ab](https://github.com/nuxt-community/axios-module/commit/66d56ab8adbb50b470bc298d27bcd1a6820ab958)) 25 | 26 | ### [5.13.3](https://github.com/nuxt-community/axios-module/compare/v5.13.2...v5.13.3) (2021-05-17) 27 | 28 | 29 | ### Bug Fixes 30 | 31 | * transpile defu ([cf1a03f](https://github.com/nuxt-community/axios-module/commit/cf1a03f99a2591bd60160292864b7e16f86eb5cf)), closes [unjs/defu#28](https://github.com/unjs/defu/issues/28) 32 | 33 | ### [5.13.2](https://github.com/nuxt-community/axios-module/compare/v5.13.1...v5.13.2) (2021-05-17) 34 | 35 | ### [5.13.1](https://github.com/nuxt-community/axios-module/compare/v5.13.0...v5.13.1) (2021-02-08) 36 | 37 | 38 | ### Bug Fixes 39 | 40 | * **types:** add missing type for `create()` ([#475](https://github.com/nuxt-community/axios-module/issues/475)) ([62f17ca](https://github.com/nuxt-community/axios-module/commit/62f17ca2ba005a74762f67b004ebcc7b612425ac)) 41 | * **types:** update interceptors type ([#476](https://github.com/nuxt-community/axios-module/issues/476)) ([ecfab9a](https://github.com/nuxt-community/axios-module/commit/ecfab9a7cf655737af46dd02ba013c5600b81e82)) 42 | 43 | ## [5.13.0](https://github.com/nuxt-community/axios-module/compare/v5.12.5...v5.13.0) (2021-02-01) 44 | 45 | 46 | ### Features 47 | 48 | * support baseUrl and browserBaseUrl to handle casing typos ([8904847](https://github.com/nuxt-community/axios-module/commit/890484755c1897da8dd80c155fba2328c05f58f8)) 49 | 50 | 51 | ### Bug Fixes 52 | 53 | * add `x-forwarded-port` and `x-forwarded-proto` to `proxyHeaderIgnore` defaults ([#465](https://github.com/nuxt-community/axios-module/issues/465)) ([a1a1894](https://github.com/nuxt-community/axios-module/commit/a1a189486d63356433c939529d6e631f3fc9f923)) 54 | 55 | ### [5.12.5](https://github.com/nuxt-community/axios-module/compare/v5.12.4...v5.12.5) (2021-01-04) 56 | 57 | 58 | ### Bug Fixes 59 | 60 | * add `x-forwarded-host` to `proxyHeaderIgnore` defaults ([#462](https://github.com/nuxt-community/axios-module/issues/462)) ([433548b](https://github.com/nuxt-community/axios-module/commit/433548b1ca0e3ad22b9237add9093501fb2f7bfb)), closes [#456](https://github.com/nuxt-community/axios-module/issues/456) 61 | 62 | ### [5.12.4](https://github.com/nuxt-community/axios-module/compare/v5.12.3...v5.12.4) (2020-12-14) 63 | 64 | 65 | ### Bug Fixes 66 | 67 | * preserve default headers with custom headers ([#452](https://github.com/nuxt-community/axios-module/issues/452)) ([55f994f](https://github.com/nuxt-community/axios-module/commit/55f994f1627798f36174a14edd28fe7a5e4e70e7)) 68 | 69 | ### [5.12.3](https://github.com/nuxt-community/axios-module/compare/v5.12.2...v5.12.3) (2020-11-30) 70 | 71 | 72 | ### Bug Fixes 73 | 74 | * `$loading().set(Infinity)` issue ([#424](https://github.com/nuxt-community/axios-module/issues/424)) ([7b32262](https://github.com/nuxt-community/axios-module/commit/7b322620f1349e393338fbd7388b92b0e9275fba)) 75 | 76 | ### [5.12.2](https://github.com/nuxt-community/axios-module/compare/v5.12.1...v5.12.2) (2020-08-25) 77 | 78 | 79 | ### Bug Fixes 80 | 81 | * **types:** extend Axios.AxiosRequestConfig with "progress" option ([#408](https://github.com/nuxt-community/axios-module/issues/408)) ([ea4ea7e](https://github.com/nuxt-community/axios-module/commit/ea4ea7e323e053d6ae025210534c675e468a273c)) 82 | 83 | ### Docs 84 | 85 | * Migrate docs to nuxt/content ([#404](https://github.com/nuxt-community/axios-module/pull/404)) 86 | 87 | ### [5.12.1](https://github.com/nuxt-community/axios-module/compare/v5.12.0...v5.12.1) (2020-08-05) 88 | 89 | 90 | ### Bug Fixes 91 | 92 | * **plugin:** hide progress-bar on cancelled requests ([#398](https://github.com/nuxt-community/axios-module/issues/398)) ([2061721](https://github.com/nuxt-community/axios-module/commit/206172133e8cf3e8dc4f28efe34da695f2cb64f4)) 93 | 94 | ## [5.12.0](https://github.com/nuxt-community/axios-module/compare/v5.11.0...v5.12.0) (2020-07-10) 95 | 96 | 97 | ### Features 98 | 99 | * **plugin:** support runtimeConfig ([#387](https://github.com/nuxt-community/axios-module/issues/387)) ([351ea5e](https://github.com/nuxt-community/axios-module/commit/351ea5ee459eea53b9124de75ebfa7674d7ccd40)) 100 | 101 | 102 | ### Bug Fixes 103 | 104 | * **types:** add axios-retry type def for more options ([#378](https://github.com/nuxt-community/axios-module/issues/378)) ([40a0c58](https://github.com/nuxt-community/axios-module/commit/40a0c5885819406fec88b212f0219539fbc0d229)) 105 | * **types:** add prefix, port, host options to axios types ([#381](https://github.com/nuxt-community/axios-module/issues/381)) ([301805b](https://github.com/nuxt-community/axios-module/commit/301805b5eade85ff30f80e9f34341d586a056d8b)) 106 | 107 | ## [5.11.0](https://github.com/nuxt-community/axios-module/compare/v5.10.3...v5.11.0) (2020-06-05) 108 | 109 | 110 | ### Features 111 | 112 | * experimental runtimeConfig support ([07ca13c](https://github.com/nuxt-community/axios-module/commit/07ca13c58194c8c48a61896a07505a936c26eb93)) 113 | 114 | 115 | ### Bug Fixes 116 | 117 | * **plugin:** always get global `$nuxt` while loading ([#364](https://github.com/nuxt-community/axios-module/issues/364)) ([e848b9d](https://github.com/nuxt-community/axios-module/commit/e848b9d0b0a1804388eb51d328ab6054d89aa979)) 118 | 119 | ### [5.10.3](https://github.com/nuxt-community/axios-module/compare/v5.10.2...v5.10.3) (2020-04-30) 120 | 121 | 122 | ### Bug Fixes 123 | 124 | * globalName fallback for nuxt < 2.2.0 ([12da6c8](https://github.com/nuxt-community/axios-module/commit/12da6c8e2feb8cf4f7e918fbbe4693400152c1ff)) 125 | 126 | ### [5.10.2](https://github.com/nuxt-community/axios-module/compare/v5.10.1...v5.10.2) (2020-04-27) 127 | 128 | 129 | ### Bug Fixes 130 | 131 | * **plugin:** add missing $ prefix to globalName ([#356](https://github.com/nuxt-community/axios-module/issues/356)) ([47788bd](https://github.com/nuxt-community/axios-module/commit/47788bdd0384807c9d63aa3caa7f2031f44d4c96)) 132 | 133 | ### [5.10.1](https://github.com/nuxt-community/axios-module/compare/v5.10.0...v5.10.1) (2020-04-22) 134 | 135 | ## [5.10.0](https://github.com/nuxt-community/axios-module/compare/v5.9.7...v5.10.0) (2020-04-21) 136 | 137 | 138 | ### Features 139 | 140 | * **plugin:** enable server brotli if supported (closes [#276](https://github.com/nuxt-community/axios-module/issues/276)) ([074f98c](https://github.com/nuxt-community/axios-module/commit/074f98cbdf409473357b2cd24cd6cb13fe75f149)) 141 | 142 | 143 | ### Bug Fixes 144 | 145 | * **module:** browserBaseURL as empty string (fixes [#303](https://github.com/nuxt-community/axios-module/issues/303)) ([18afe5c](https://github.com/nuxt-community/axios-module/commit/18afe5c1a9aac6380bdd5ffb337a0968a6d504aa)) 146 | * **plugin:** preserve default headers (fixes [#323](https://github.com/nuxt-community/axios-module/issues/323)) ([6c5605d](https://github.com/nuxt-community/axios-module/commit/6c5605df0b77e9e4df32ad1eaecb2eac60eb1c1d)) 147 | * **plugin:** use `globalName` instead of `$nuxt` (fixes [#345](https://github.com/nuxt-community/axios-module/issues/345)) ([fd1f8ec](https://github.com/nuxt-community/axios-module/commit/fd1f8ec17160f6e88610e3dfa2153423b3140592)) 148 | 149 | ### [5.9.7](https://github.com/nuxt-community/axios-module/compare/v5.9.6...v5.9.7) (2020-03-30) 150 | 151 | 152 | ### Bug Fixes 153 | 154 | * **plugin:** don't convert falsy urls to string ([#347](https://github.com/nuxt-community/axios-module/issues/347)) ([b8a510e](https://github.com/nuxt-community/axios-module/commit/b8a510ee989fabf10d93d99a7ae1e17c0fc3eca0)) 155 | 156 | ### [5.9.6](https://github.com/nuxt-community/axios-module/compare/v5.9.5...v5.9.6) (2020-03-27) 157 | 158 | 159 | ### Bug Fixes 160 | 161 | * **module:** always set protocol to `https` when `https: true` is set ([#344](https://github.com/nuxt-community/axios-module/issues/344)) ([6f82570](https://github.com/nuxt-community/axios-module/commit/6f82570b163c4d4635321601f05d0c4641a00f19)) 162 | 163 | ### [5.9.5](https://github.com/nuxt-community/axios-module/compare/v5.9.3...v5.9.5) (2020-02-02) 164 | 165 | 166 | ### Bug Fixes 167 | 168 | * **types:** add `setBaseURL` ([#329](https://github.com/nuxt-community/axios-module/issues/329)) ([9d00d6a](https://github.com/nuxt-community/axios-module/commit/9d00d6a9b5e21396d3b195f824dd2cfe99ca9012)) 169 | 170 | ### [5.9.4](https://github.com/nuxt-community/axios-module/compare/v5.9.3...v5.9.4) (2020-01-30) 171 | 172 | 173 | ### Bug Fixes 174 | 175 | * **types:** add `setBaseURL` ([#329](https://github.com/nuxt-community/axios-module/issues/329)) ([9d00d6a](https://github.com/nuxt-community/axios-module/commit/9d00d6a9b5e21396d3b195f824dd2cfe99ca9012)) 176 | 177 | ### [5.9.3](https://github.com/nuxt-community/axios-module/compare/v5.9.2...v5.9.3) (2020-01-11) 178 | 179 | 180 | ### Bug Fixes 181 | 182 | * **types:** extend from `AxiosStatic` ([#319](https://github.com/nuxt-community/axios-module/issues/319)) ([9223a57](https://github.com/nuxt-community/axios-module/commit/9223a57c7ac65b2c414858360126d23bf60f9c82)) 183 | 184 | ### [5.9.2](https://github.com/nuxt-community/axios-module/compare/v5.9.1...v5.9.2) (2020-01-02) 185 | 186 | ### [5.9.1](https://github.com/nuxt-community/axios-module/compare/v5.9.0...v5.9.1) (2020-01-02) 187 | 188 | ## [5.9.0](https://github.com/nuxt-community/axios-module/compare/v5.6.0...v5.9.0) (2019-12-17) 189 | 190 | 191 | ### Features 192 | 193 | * add `CancelToken` and `isCancel` to axios instance ([#292](https://github.com/nuxt-community/axios-module/issues/292)) ([474910b](https://github.com/nuxt-community/axios-module/commit/474910bd875f2d1f6bf0e39e511db87b08673cdc)) 194 | * add function helper `setBaseURL` ([#296](https://github.com/nuxt-community/axios-module/issues/296)) ([c429d55](https://github.com/nuxt-community/axios-module/commit/c429d555202620343bc79b70bad3aa61958fb368)) 195 | * allow adding custom headers with nuxt config ([#294](https://github.com/nuxt-community/axios-module/issues/294)) ([af1e86d](https://github.com/nuxt-community/axios-module/commit/af1e86d80065951a2ea47cdb291d159bf174f73a)) 196 | * allow creating new instances ([#306](https://github.com/nuxt-community/axios-module/issues/306)) ([2ca95e5](https://github.com/nuxt-community/axios-module/commit/2ca95e58235f10b22317a7c3d53d539d8006f528)) 197 | 198 | 199 | ### Bug Fixes 200 | 201 | * **docs:** should be response.code instead of code ([#197](https://github.com/nuxt-community/axios-module/issues/197)) ([d07102e](https://github.com/nuxt-community/axios-module/commit/d07102e51f9089988ba2b0184dd442ad4fc9d46a)) 202 | * **headers:** don't proxy `content-md5` and `content-type` ([#300](https://github.com/nuxt-community/axios-module/issues/300)) ([46c49e2](https://github.com/nuxt-community/axios-module/commit/46c49e253cb23ffc1cf92ad02a1ab1fc24034906)) 203 | * **progress:** handle canceled requests ([#301](https://github.com/nuxt-community/axios-module/issues/301)) ([2903fd5](https://github.com/nuxt-community/axios-module/commit/2903fd579fe5deed693b26660a687089a589ebdf)) 204 | * **types:** correct Vuex Store instance ([#227](https://github.com/nuxt-community/axios-module/issues/227)) ([e5747eb](https://github.com/nuxt-community/axios-module/commit/e5747ebb275be56cb4496771911419038952bf4b)) 205 | * use `Axios` for `isCancel` (fixes [#301](https://github.com/nuxt-community/axios-module/issues/301)) ([4f71479](https://github.com/nuxt-community/axios-module/commit/4f714791b564b91b915c107299bb3ffecc3a482b)) 206 | 207 | ## [5.8.0](https://github.com/nuxt-community/axios-module/compare/v5.7.1...v5.8.0) (2019-10-23) 208 | 209 | 210 | ### Features 211 | 212 | * add `CancelToken` and `isCancel` to axios instance ([#292](https://github.com/nuxt-community/axios-module/issues/292)) ([b9335b1](https://github.com/nuxt-community/axios-module/commit/b9335b1c55b3af34e2d6e5897fedb8372a620ce4)) 213 | 214 | ### [5.7.1](https://github.com/nuxt-community/axios-module/compare/v5.7.0...v5.7.1) (2019-10-22) 215 | 216 | 217 | ### Bug Fixes 218 | 219 | * use `Axios` for `isCancel` (fixes [#301](https://github.com/nuxt-community/axios-module/issues/301)) ([82dfccc](https://github.com/nuxt-community/axios-module/commit/82dfccce409e918a91e498af1340408dc0892bf5)) 220 | 221 | ## [5.7.0](https://github.com/nuxt-community/axios-module/compare/v5.6.0...v5.7.0) (2019-10-22) 222 | 223 | 224 | ### Features 225 | 226 | * add function helper `setBaseURL` ([#296](https://github.com/nuxt-community/axios-module/issues/296)) ([1028bbc](https://github.com/nuxt-community/axios-module/commit/1028bbcaf2d1a29a33949f05aeb9d519c30b246e)) 227 | * allow adding custom headers with nuxt config ([#294](https://github.com/nuxt-community/axios-module/issues/294)) ([3e38906](https://github.com/nuxt-community/axios-module/commit/3e3890616a5ac3eb34b07ec476313bb648aca59a)) 228 | 229 | 230 | ### Bug Fixes 231 | 232 | * **headers:** don't proxy `content-md5` and `content-type` ([#300](https://github.com/nuxt-community/axios-module/issues/300)) ([f959c58](https://github.com/nuxt-community/axios-module/commit/f959c585254029ac8d623d1472b883022ab115e2)) 233 | * **progress:** handle canceled requests ([#301](https://github.com/nuxt-community/axios-module/issues/301)) ([5096060](https://github.com/nuxt-community/axios-module/commit/50960609d913d059758658aa88434bd28faa0c47)) 234 | 235 | ## [5.6.0](https://github.com/nuxt-community/axios-module/compare/v5.5.4...v5.6.0) (2019-08-20) 236 | 237 | 238 | ### Features 239 | 240 | * **types:** provide nuxt 2.9 compatible types ([#277](https://github.com/nuxt-community/axios-module/issues/277)) ([7aee77b](https://github.com/nuxt-community/axios-module/commit/7aee77b)) 241 | * https detection ([#260](https://github.com/nuxt-community/axios-module/issues/260)) ([953ab8c](https://github.com/nuxt-community/axios-module/commit/953ab8c)) 242 | 243 | 244 | 245 | ### [5.5.4](https://github.com/nuxt-community/axios-module/compare/v5.5.3...v5.5.4) (2019-06-05) 246 | 247 | 248 | ### Bug Fixes 249 | 250 | * ignore content-length header ([41ff27a](https://github.com/nuxt-community/axios-module/commit/41ff27a)) 251 | 252 | 253 | 254 | ### [5.5.3](https://github.com/nuxt-community/axios-module/compare/v5.5.2...v5.5.3) (2019-05-30) 255 | 256 | 257 | ### Bug Fixes 258 | 259 | * bump axios to ^0.19.0 ([ee8f999](https://github.com/nuxt-community/axios-module/commit/ee8f999)) 260 | 261 | 262 | 263 | ## [5.5.2](https://github.com/nuxt-community/axios-module/compare/v5.5.1...v5.5.2) (2019-05-26) 264 | 265 | 266 | ### Bug Fixes 267 | 268 | * vuex typescript type ([#253](https://github.com/nuxt-community/axios-module/issues/253)) ([9205fdf](https://github.com/nuxt-community/axios-module/commit/9205fdf)) 269 | 270 | 271 | 272 | ## [5.5.1](https://github.com/nuxt-community/axios-module/compare/v5.5.0...v5.5.1) (2019-05-23) 273 | 274 | 275 | ### Bug Fixes 276 | 277 | * don't toLowerCase headers for `setHeader` and `setToken` ([#250](https://github.com/nuxt-community/axios-module/issues/250)) ([93469f0](https://github.com/nuxt-community/axios-module/commit/93469f0)) 278 | 279 | 280 | 281 | # [5.5.0](https://github.com/nuxt-community/axios-module/compare/v5.4.2...v5.5.0) (2019-05-22) 282 | 283 | 284 | ### Bug Fixes 285 | 286 | * lowercase `accept-encoding` header (nuxt/http[#43](https://github.com/nuxt-community/axios-module/issues/43)) ([c17fec2](https://github.com/nuxt-community/axios-module/commit/c17fec2)) 287 | 288 | 289 | ### Features 290 | 291 | * convert header names to lowercase (nuxt/http[#45](https://github.com/nuxt-community/axios-module/issues/45)) ([2e514a4](https://github.com/nuxt-community/axios-module/commit/2e514a4)) 292 | * use `server` of nuxt.config.js to set default baseURL ([#245](https://github.com/nuxt-community/axios-module/issues/245)) ([e1120a9](https://github.com/nuxt-community/axios-module/commit/e1120a9)) 293 | 294 | 295 | 296 | ## [5.4.1](https://github.com/nuxt-community/axios-module/compare/v5.4.0...v5.4.1) (2019-03-05) 297 | 298 | 299 | ### Bug Fixes 300 | 301 | * **types:** correct Vuex Store instance ([#227](https://github.com/nuxt-community/axios-module/issues/227)) ([1ed6e2f](https://github.com/nuxt-community/axios-module/commit/1ed6e2f)) 302 | 303 | 304 | 305 | # [5.4.0](https://github.com/nuxt-community/axios-module/compare/v5.3.6...v5.4.0) (2019-03-02) 306 | 307 | 308 | ### Bug Fixes 309 | 310 | * **types:** `onResponseError` typo ([#203](https://github.com/nuxt-community/axios-module/issues/203)) ([5fc1441](https://github.com/nuxt-community/axios-module/commit/5fc1441)) 311 | * **types:** add AxiosError interface ([efb7191](https://github.com/nuxt-community/axios-module/commit/efb7191)) 312 | * **types:** move types in types folder ([deb2834](https://github.com/nuxt-community/axios-module/commit/deb2834)) 313 | 314 | 315 | ### Features 316 | 317 | * **types:** add Context interface ([7f8952a](https://github.com/nuxt-community/axios-module/commit/7f8952a)) 318 | * **types:** add types for helper functions ([#193](https://github.com/nuxt-community/axios-module/issues/193)) ([79909cc](https://github.com/nuxt-community/axios-module/commit/79909cc)) 319 | 320 | 321 | 322 | 323 | ## [5.3.6](https://github.com/nuxt-community/axios-module/compare/v5.3.5...v5.3.6) (2018-11-08) 324 | 325 | 326 | ### Bug Fixes 327 | 328 | * correctly ignore brotli encoding on server-side ([#180](https://github.com/nuxt-community/axios-module/issues/180)) ([4a52bfd](https://github.com/nuxt-community/axios-module/commit/4a52bfd)) 329 | 330 | 331 | 332 | 333 | ## [5.3.5](https://github.com/nuxt-community/axios-module/compare/v5.3.4...v5.3.5) (2018-11-07) 334 | 335 | 336 | ### Bug Fixes 337 | 338 | * **defaults:** ignore `cf-ray` and `cf-connecting-ip` headers on server side ([#20](https://github.com/nuxt-community/axios-module/issues/20)) ([#175](https://github.com/nuxt-community/axios-module/issues/175)) ([3ae5416](https://github.com/nuxt-community/axios-module/commit/3ae5416)) 339 | * **defaults:** set proper Accept-Encoding for server side ([#176](https://github.com/nuxt-community/axios-module/issues/176)) ([c84fb56](https://github.com/nuxt-community/axios-module/commit/c84fb56)) 340 | 341 | 342 | 343 | 344 | ## [5.3.4](https://github.com/nuxt-community/axios-module/compare/v5.3.3...v5.3.4) (2018-10-30) 345 | 346 | 347 | 348 | 349 | ## [5.3.3](https://github.com/nuxt-community/axios-module/compare/v5.3.2...v5.3.3) (2018-09-28) 350 | 351 | 352 | ### Bug Fixes 353 | 354 | * **package:** add missing types from index.d.ts ([3a06503](https://github.com/nuxt-community/axios-module/commit/3a06503)) 355 | 356 | 357 | 358 | 359 | ## [5.3.2](https://github.com/nuxt-community/axios-module/compare/v5.3.1...v5.3.2) (2018-09-21) 360 | 361 | 362 | ### Bug Fixes 363 | 364 | * **types:** replace AxiosPromise to Promise ([#162](https://github.com/nuxt-community/axios-module/issues/162)) ([5fd9214](https://github.com/nuxt-community/axios-module/commit/5fd9214)) 365 | 366 | 367 | 368 | 369 | ## [5.3.1](https://github.com/nuxt-community/axios-module/compare/v5.3.0...v5.3.1) (2018-03-31) 370 | 371 | 372 | 373 | 374 | # [5.3.0](https://github.com/nuxt-community/axios-module/compare/v5.2.0...v5.3.0) (2018-03-31) 375 | 376 | 377 | ### Features 378 | 379 | * CLI improvements ([481e6da](https://github.com/nuxt-community/axios-module/commit/481e6da)) 380 | 381 | 382 | 383 | 384 | # [5.2.0](https://github.com/nuxt-community/axios-module/compare/v5.1.1...v5.2.0) (2018-03-31) 385 | 386 | 387 | ### Bug Fixes 388 | 389 | * **progress:** onProgress when currentRequests is zero ([#118](https://github.com/nuxt-community/axios-module/issues/118)) ([a90236e](https://github.com/nuxt-community/axios-module/commit/a90236e)) 390 | 391 | 392 | ### Features 393 | 394 | * consola integration ([4ec3b5d](https://github.com/nuxt-community/axios-module/commit/4ec3b5d)) 395 | 396 | 397 | 398 | 399 | ## [5.1.1](https://github.com/nuxt-community/axios-module/compare/v5.1.0...v5.1.1) (2018-03-06) 400 | 401 | 402 | ### Bug Fixes 403 | 404 | * **progress:** handle division by zero ([#117](https://github.com/nuxt-community/axios-module/issues/117)) ([040eaf7](https://github.com/nuxt-community/axios-module/commit/040eaf7)), closes [#166](https://github.com/nuxt-community/axios-module/issues/166) 405 | 406 | 407 | 408 | 409 | # [5.1.0](https://github.com/nuxt-community/axios-module/compare/v5.0.1...v5.1.0) (2018-03-05) 410 | 411 | 412 | ### Features 413 | 414 | * allow disable progress per request. closes [#112](https://github.com/nuxt-community/axios-module/issues/112). ([1530bb6](https://github.com/nuxt-community/axios-module/commit/1530bb6)) 415 | * disable https for localhost url ([#93](https://github.com/nuxt-community/axios-module/issues/93)) ([dd67734](https://github.com/nuxt-community/axios-module/commit/dd67734)) 416 | 417 | 418 | 419 | 420 | ## [5.0.1](https://github.com/nuxt-community/axios-module/compare/v5.0.0...v5.0.1) (2018-02-08) 421 | 422 | 423 | ### Bug Fixes 424 | 425 | * don't mutate env.API_URL ([a8ea331](https://github.com/nuxt-community/axios-module/commit/a8ea331)) 426 | 427 | 428 | 429 | 430 | # [5.0.0](https://github.com/nuxt-community/axios-module/compare/v5.0.0-rc.2...v5.0.0) (2018-02-04) 431 | 432 | 433 | ### Bug Fixes 434 | 435 | * **progress:** finish on fail ([ea7b569](https://github.com/nuxt-community/axios-module/commit/ea7b569)) 436 | 437 | 438 | ### Features 439 | 440 | * https option ([#57](https://github.com/nuxt-community/axios-module/issues/57)) ([9ecb547](https://github.com/nuxt-community/axios-module/commit/9ecb547)) 441 | * passing options via proxy option ([a923db3](https://github.com/nuxt-community/axios-module/commit/a923db3)) 442 | * support retry with axios-retry ([7221cac](https://github.com/nuxt-community/axios-module/commit/7221cac)), closes [#77](https://github.com/nuxt-community/axios-module/issues/77) 443 | 444 | 445 | 446 | 447 | # [5.0.0-rc.2](https://github.com/nuxt-community/axios-module/compare/v5.0.0-rc.1...v5.0.0-rc.2) (2018-01-29) 448 | 449 | 450 | ### Bug Fixes 451 | 452 | * **package:** require [@nuxtjs](https://github.com/nuxtjs)/proxy as a peerDependency ([fd1ef47](https://github.com/nuxt-community/axios-module/commit/fd1ef47)) 453 | * support dynamic API_URL for SSR ([ea4882a](https://github.com/nuxt-community/axios-module/commit/ea4882a)) 454 | 455 | 456 | 457 | 458 | # [5.0.0-rc.1](https://github.com/nuxt-community/axios-module/compare/v5.0.0-rc.0...v5.0.0-rc.1) (2018-01-28) 459 | 460 | 461 | ### Bug Fixes 462 | 463 | * **progress:** ensure $loading is valid ([cbdc586](https://github.com/nuxt-community/axios-module/commit/cbdc586)) 464 | 465 | 466 | 467 | 468 | # [5.0.0-rc.0](https://github.com/nuxt-community/axios-module/compare/v5.0.0-alpha.1...v5.0.0-rc.0) (2018-01-28) 469 | 470 | 471 | ### Features 472 | 473 | * support proxy ([0d3be17](https://github.com/nuxt-community/axios-module/commit/0d3be17)) 474 | 475 | 476 | 477 | 478 | # [5.0.0-alpha.1](https://github.com/nuxt-community/axios-module/compare/v5.0.0-alpha.0...v5.0.0-alpha.1) (2018-01-28) 479 | 480 | 481 | ### Features 482 | 483 | * integrate with nuxt progress bar ([41a0964](https://github.com/nuxt-community/axios-module/commit/41a0964)) 484 | 485 | 486 | 487 | 488 | # [5.0.0-alpha.0](https://github.com/nuxt-community/axios-module/compare/v4.5.2...v5.0.0-alpha.0) (2018-01-28) 489 | 490 | 491 | ### Code Refactoring 492 | 493 | * a better and more stable way to specify baseURL and browserBaseURL options ([533cf4e](https://github.com/nuxt-community/axios-module/commit/533cf4e)) 494 | 495 | 496 | ### Features 497 | 498 | * interceptor helpers ([fa3eb47](https://github.com/nuxt-community/axios-module/commit/fa3eb47)) 499 | * rewrite plugin ([647b58f](https://github.com/nuxt-community/axios-module/commit/647b58f)) 500 | 501 | 502 | ### BREAKING CHANGES 503 | 504 | * prefix should be set to `/api` for backward compability. refer to new docs. 505 | 506 | 507 | 508 | 509 | ## [4.5.2](https://github.com/nuxt-community/axios-module/compare/v4.5.1...v4.5.2) (2017-12-29) 510 | 511 | 512 | 513 | 514 | ## [4.5.1](https://github.com/nuxt-community/axios-module/compare/v4.5.0...v4.5.1) (2017-12-29) 515 | 516 | 517 | 518 | 519 | # [4.5.0](https://github.com/nuxt-community/axios-module/compare/v4.4.0...v4.5.0) (2017-11-16) 520 | 521 | 522 | ### Bug Fixes 523 | 524 | * link to the proxy page ([5449939](https://github.com/nuxt-community/axios-module/commit/5449939)) 525 | 526 | 527 | ### Features 528 | 529 | * disable sefault error handler ([#44](https://github.com/nuxt-community/axios-module/issues/44)) ([f1e95ff](https://github.com/nuxt-community/axios-module/commit/f1e95ff)) 530 | 531 | 532 | 533 | 534 | # [4.4.0](https://github.com/nuxt-community/axios-module/compare/v4.3.1...v4.4.0) (2017-09-30) 535 | 536 | 537 | ### Features 538 | 539 | * **proxyHeader:** proxyHeadersIgnore option ([7c13655](https://github.com/nuxt-community/axios-module/commit/7c13655)) 540 | 541 | 542 | 543 | 544 | ## [4.3.1](https://github.com/nuxt-community/axios-module/compare/v4.3.0...v4.3.1) (2017-09-28) 545 | 546 | 547 | 548 | 549 | # [4.3.0](https://github.com/nuxt-community/axios-module/compare/v4.2.1...v4.3.0) (2017-09-11) 550 | 551 | 552 | ### Features 553 | 554 | * don't rely on hostname for default values ([dadd7d8](https://github.com/nuxt-community/axios-module/commit/dadd7d8)) 555 | 556 | 557 | 558 | 559 | ## [4.2.1](https://github.com/nuxt-community/axios-module/compare/v4.2.0...v4.2.1) (2017-09-08) 560 | 561 | 562 | 563 | 564 | # [4.2.0](https://github.com/nuxt-community/axios-module/compare/v4.1.1...v4.2.0) (2017-09-08) 565 | 566 | 567 | ### Features 568 | 569 | * pass ctx to errorHandlers ([c70749a](https://github.com/nuxt-community/axios-module/commit/c70749a)) 570 | 571 | 572 | 573 | 574 | ## [4.1.1](https://github.com/nuxt-community/axios-module/compare/v4.1.0...v4.1.1) (2017-09-06) 575 | 576 | 577 | ### Bug Fixes 578 | 579 | * delete accept header ([2f04e30](https://github.com/nuxt-community/axios-module/commit/2f04e30)), closes [#12](https://github.com/nuxt-community/axios-module/issues/12) 580 | 581 | 582 | 583 | 584 | # [4.1.0](https://github.com/nuxt-community/axios-module/compare/v4.0.1...v4.1.0) (2017-09-06) 585 | 586 | 587 | ### Bug Fixes 588 | 589 | * inject $axios in current ctx ([356b31f](https://github.com/nuxt-community/axios-module/commit/356b31f)) 590 | 591 | 592 | ### Features 593 | 594 | * add options.init ([8e0c0e8](https://github.com/nuxt-community/axios-module/commit/8e0c0e8)) 595 | 596 | 597 | ### Performance Improvements 598 | 599 | * move init outside of plugin ([bcd4710](https://github.com/nuxt-community/axios-module/commit/bcd4710)) 600 | 601 | 602 | 603 | 604 | ## [4.0.1](https://github.com/nuxt-community/axios-module/compare/v4.0.0...v4.0.1) (2017-09-04) 605 | 606 | 607 | ### Bug Fixes 608 | 609 | * **package:** make nuxt devDependency ([a36a886](https://github.com/nuxt-community/axios-module/commit/a36a886)) 610 | 611 | 612 | 613 | 614 | # [4.0.0](https://github.com/nuxt-community/axios-module/compare/v3.1.4...v4.0.0) (2017-08-30) 615 | 616 | 617 | ### Features 618 | 619 | * better baseURL message ([61432a1](https://github.com/nuxt-community/axios-module/commit/61432a1)) 620 | * responseInterceptor and errorHandler ([b16d6bf](https://github.com/nuxt-community/axios-module/commit/b16d6bf)) 621 | * upgrade for nuxt rc8 ([a341185](https://github.com/nuxt-community/axios-module/commit/a341185)) 622 | 623 | 624 | ### BREAKING CHANGES 625 | 626 | * app.axios is not available anymore (without $) should always use app.$axios 627 | 628 | 629 | 630 | 631 | ## [3.1.4](https://github.com/nuxt-community/axios-module/compare/v3.1.3...v3.1.4) (2017-08-13) 632 | 633 | 634 | ### Bug Fixes 635 | 636 | * create fresh objects for all default header scopes ([7ba3ae8](https://github.com/nuxt-community/axios-module/commit/7ba3ae8)) 637 | 638 | 639 | 640 | 641 | ## [3.1.3](https://github.com/nuxt-community/axios-module/compare/v3.1.1...v3.1.3) (2017-08-13) 642 | 643 | ### Bug Fixes 644 | 645 | * **headers:** fix security bug with default request headers ([9355228](https://github.com/nuxt-community/axios-module/commit/9355228)) 646 | 647 | 648 | 649 | 650 | ## 3.1.1 (2017-08-13) 651 | (repository moved from nuxt-community/modules) 652 | 653 | ### Features 654 | 655 | * **axios:** fetch style requests 656 | 657 | 658 | ## [3.0.1](https://github.com/nuxt/modules/compare/@nuxtjs/axios@3.0.0...@nuxtjs/axios@3.0.1) (2017-07-25) 659 | 660 | 661 | ### Bug Fixes 662 | 663 | * **axios:** typo in default headers ([9697559](https://github.com/nuxt/modules/commit/9697559)) 664 | 665 | 666 | 667 | 668 | 669 | # [3.0.0](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.3.0...@nuxtjs/axios@3.0.0) (2017-07-25) 670 | 671 | 672 | ### Code Refactoring 673 | 674 | * **axios:** remove $ shortcut mixins ([1ab2bd6](https://github.com/nuxt/modules/commit/1ab2bd6)) 675 | 676 | 677 | ### BREAKING CHANGES 678 | 679 | * **axios:** You have to explicitly use `this.$axios.[method]` instead of `this.$[method]` 680 | 681 | 682 | 683 | 684 | 685 | # [2.3.0](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.2.4...@nuxtjs/axios@2.3.0) (2017-07-24) 686 | 687 | 688 | ### Features 689 | 690 | * **axios:** optionally disable error handling (#74) ([a195feb](https://github.com/nuxt/modules/commit/a195feb)) 691 | * **axios:** redirectError ([4ce1a1c](https://github.com/nuxt/modules/commit/4ce1a1c)) 692 | 693 | 694 | 695 | 696 | 697 | ## [2.2.4](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.2.3...@nuxtjs/axios@2.2.4) (2017-07-20) 698 | 699 | 700 | ### Bug Fixes 701 | 702 | * **axios:** temporary fix for nuxt/nuxt.js#1127 ([499b639](https://github.com/nuxt/modules/commit/499b639)), closes [nuxt/nuxt.js#1127](https://github.com/nuxt/nuxt.js/issues/1127) 703 | 704 | 705 | 706 | 707 | 708 | ## [2.2.3](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.2.1...@nuxtjs/axios@2.2.3) (2017-07-19) 709 | 710 | 711 | ### Bug Fixes 712 | 713 | * **axios:** don't proxy Host header from request (#72, #39) ([61462ca](https://github.com/nuxt/modules/commit/61462ca)) 714 | 715 | 716 | 717 | 718 | 719 | ## [2.2.2](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.2.1...@nuxtjs/axios@2.2.2) (2017-07-19) 720 | 721 | 722 | ### Bug Fixes 723 | 724 | * **axios:** don't proxy Host header from request (#72, #39) ([61462ca](https://github.com/nuxt/modules/commit/61462ca)) 725 | 726 | 727 | 728 | 729 | 730 | ## [2.2.1](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.2.0...@nuxtjs/axios@2.2.1) (2017-07-15) 731 | 732 | 733 | ### Bug Fixes 734 | 735 | * **axios:** problems related to #65 ([4e7dd3f](https://github.com/nuxt/modules/commit/4e7dd3f)) 736 | 737 | 738 | 739 | 740 | 741 | ## [2.0.3](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.0.2...@nuxtjs/axios@2.0.3) (2017-06-10) 742 | 743 | 744 | ### Bug Fixes 745 | 746 | * **axios:** Handle relative baseURL ([19b8453](https://github.com/nuxt/modules/commit/19b8453)) 747 | * handle 0.0.0.0 host ([610e0f5](https://github.com/nuxt/modules/commit/610e0f5)) 748 | 749 | 750 | 751 | 752 | 753 | ## [2.0.2](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.0.1...@nuxtjs/axios@2.0.2) (2017-06-09) 754 | 755 | 756 | ### Bug Fixes 757 | 758 | * **axios:** Node 6.x support ([54deac0](https://github.com/nuxt/modules/commit/54deac0)) 759 | 760 | 761 | 762 | 763 | 764 | ## [2.0.1](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.0.0...@nuxtjs/axios@2.0.1) (2017-06-09) 765 | 766 | 767 | ### Bug Fixes 768 | 769 | * **axios:** ensure store exists before injecting ([23ad7b7](https://github.com/nuxt/modules/commit/23ad7b7)) 770 | 771 | 772 | 773 | 774 | 775 | # [2.0.0](https://github.com/nuxt/modules/compare/@nuxtjs/axios@1.0.2...@nuxtjs/axios@2.0.0) (2017-06-09) 776 | 777 | 778 | ### Bug Fixes 779 | 780 | * **axios:** install using Vue.use ([184651b](https://github.com/nuxt/modules/commit/184651b)) 781 | * **axios:** req typo ([16f28b1](https://github.com/nuxt/modules/commit/16f28b1)) 782 | * **axios:** use relative `API_URL` if same host and port else `API_URL` ([3421d19](https://github.com/nuxt/modules/commit/3421d19)) 783 | 784 | 785 | ### Features 786 | 787 | * **axios:** AXIOS_CREDENTIALS, AXIOS_SSR_HEADERS ([4dfdc2d](https://github.com/nuxt/modules/commit/4dfdc2d)) 788 | * **axios:** don't append optional config into env ([fe189e8](https://github.com/nuxt/modules/commit/fe189e8)) 789 | * **axios:** Easier API ([f54a434](https://github.com/nuxt/modules/commit/f54a434)) 790 | * **axios:** New API ([0194226](https://github.com/nuxt/modules/commit/0194226)) 791 | * **axios:** nuxt friendly errors for SSR ([65bc50f](https://github.com/nuxt/modules/commit/65bc50f)) 792 | 793 | 794 | ### BREAKING CHANGES 795 | 796 | * **axios:** API_PREFIX is deprecated. 797 | 798 | 799 | 800 | 801 | 802 | ## [1.0.2](https://github.com/nuxt/modules/compare/@nuxtjs/axios@1.0.0...@nuxtjs/axios@1.0.2) (2017-05-29) 803 | 804 | 805 | ### Bug Fixes 806 | 807 | * **axios:** remove extra function call on computed prop ([cd9da0b](https://github.com/nuxt/modules/commit/cd9da0b)) 808 | 809 | 810 | 811 | 812 | 813 | ## [1.0.1](https://github.com/nuxt/modules/compare/@nuxtjs/axios@1.0.0...@nuxtjs/axios@1.0.1) (2017-05-26) 814 | 815 | 816 | ### Bug Fixes 817 | 818 | * **axios:** remove extra function call on computed prop ([cd9da0b](https://github.com/nuxt/modules/commit/cd9da0b)) 819 | 820 | 821 | 822 | 823 | 824 | # 1.0.0 (2017-05-26) 825 | 826 | 827 | ### Features 828 | 829 | * initial migration to 1.0.0-alpha1 ([05c1b7a](https://github.com/nuxt/modules/commit/05c1b7a)) 830 | 831 | 832 | ### BREAKING CHANGES 833 | 834 | * New modules system is backward incompatible with nuxt-helpers style modules 835 | 836 | 837 | 838 | 839 | 840 | ## 0.0.1 (2017-05-10) 841 | --------------------------------------------------------------------------------