@nuxtjs/axios
Advanced tools
Comparing version 5.0.0-alpha.0 to 5.0.0-alpha.1
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="5.0.0-alpha.1"></a> | ||
# [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) | ||
### Features | ||
* integrate with nuxt progress bar ([41a0964](https://github.com/nuxt-community/axios-module/commit/41a0964)) | ||
<a name="5.0.0-alpha.0"></a> | ||
@@ -7,0 +17,0 @@ # [5.0.0-alpha.0](https://github.com/nuxt-community/axios-module/compare/v4.5.2...v5.0.0-alpha.0) (2018-01-28) |
@@ -41,2 +41,3 @@ const chalk = require('chalk') | ||
proxyHeaders: true, | ||
progress: true, | ||
proxyHeadersIgnore: ['accept', 'host'], | ||
@@ -43,0 +44,0 @@ debug: false, |
@@ -75,4 +75,3 @@ import Axios from 'axios' | ||
}) | ||
} | ||
<% } %> | ||
}<% } %> | ||
@@ -89,5 +88,48 @@ <% if (options.credentials) { %> | ||
}) | ||
} | ||
<% } %> | ||
}<% } %> | ||
<% if (options.progress) { %> | ||
const setupProgress = (axios, ctx) => { | ||
if (process.server) { | ||
return | ||
} | ||
// A noop loading inteterface for when $nuxt is not yet ready | ||
const noopLoading = { | ||
finish: () => { }, | ||
start: () => { }, | ||
fail: () => { }, | ||
set: () => { } | ||
} | ||
const $loading = () => window.$nuxt ? window.$nuxt.$loading : noopLoading | ||
let currentRequests = 0 | ||
axios.onRequest(() => { | ||
currentRequests++ | ||
}) | ||
axios.onResponse(() => { | ||
currentRequests-- | ||
if (currentRequests <= 0) { | ||
currentRequests = 0 | ||
$loading().finish() | ||
} | ||
}) | ||
axios.onError(() => { | ||
currentRequests-- | ||
$loading().fail() | ||
}) | ||
const onProgress = e => { | ||
const progress = ((e.loaded * 100) / (e.total * currentRequests)) | ||
$loading().set(progress) | ||
} | ||
axios.defaults.onUploadProgress = onProgress | ||
axios.defaults.onDownloadProgress = onProgress | ||
}<% } %> | ||
export default (ctx, inject) => { | ||
@@ -131,2 +173,3 @@ const axiosOptions = { | ||
<% if (options.credentials) { %>setupCredentialsInterceptor(axios)<% } %> | ||
<% if (options.progress) { %>setupProgress(axios, ctx)<% } %> | ||
@@ -133,0 +176,0 @@ // Inject axios to the context as $axios |
{ | ||
"name": "@nuxtjs/axios", | ||
"version": "5.0.0-alpha.0", | ||
"version": "5.0.0-alpha.1", | ||
"description": "Secure and easy axios integration with Nuxt.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -35,5 +35,20 @@ <p align="center"> | ||
## Features | ||
✓ Automatically set base URL for client & server side | ||
✓ Exposes `setToken` function to `$axios` so we can easily and globally set authentication tokens | ||
✓ Throws _nuxt-friendly_ errors and optionally redirect on specific error codes | ||
✓ Automatically enables `withCredentials` when requesting to base URL | ||
✓ Proxy request headers in SSR (Useful for auth) | ||
✓ Fetch Style requests | ||
✓ Automatically integrate with Nuxt.js progress bar | ||
# Table of Contents | ||
* [Features](#features) | ||
* [Setup](#setup) | ||
@@ -54,2 +69,3 @@ * [Usage](#usage) | ||
* [browserBaseURL](#browserbaseurl) | ||
* [progress](#progress) | ||
* [credentials](#credentials) | ||
@@ -61,11 +77,2 @@ * [debug](#debug) | ||
## Features | ||
* Automatically set base URL for client & server side | ||
* Exposes `setToken` function to `$axios` so we can easily and globally set authentication tokens | ||
* Throws _nuxt-friendly_ errors and optionally redirect on specific error codes | ||
* Automatically enables `withCredentials` when requesting to base URL | ||
* Proxy request headers in SSR (Useful for auth) | ||
* Fetch Style requests | ||
## Setup | ||
@@ -76,3 +83,3 @@ | ||
```bash | ||
>_ yarn add @nuxtjs/axios | ||
yarn add @nuxtjs/axios | ||
``` | ||
@@ -83,3 +90,3 @@ | ||
```bash | ||
>_ npm install @nuxtjs/axios | ||
npm install @nuxtjs/axios | ||
``` | ||
@@ -170,2 +177,8 @@ | ||
}) | ||
$axios.onError(error => { | ||
if (error.code === 400) { | ||
redirect('/400') | ||
} | ||
}) | ||
} | ||
@@ -299,2 +312,8 @@ ``` | ||
### `progress` | ||
* Default: `true` | ||
Integrate with Nuxt.js progress bar to show a loading bar while making requests. (Only on browser, when loading bar is available.) | ||
### `credentials` | ||
@@ -301,0 +320,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27519
219
345
0