mirror of https://github.com/sundowndev/http.git
refactor(package): update module (#206)
parent
2347b08fc2
commit
6a34d0fc0b
|
@ -23,14 +23,12 @@ jobs:
|
||||||
paths:
|
paths:
|
||||||
- "node_modules"
|
- "node_modules"
|
||||||
|
|
||||||
# Build
|
|
||||||
# - run:
|
|
||||||
# name: Build
|
|
||||||
# command: |
|
|
||||||
# mkdir -p dist
|
|
||||||
# yarn build
|
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
- run:
|
- run:
|
||||||
name: Tests
|
name: Tests
|
||||||
command: yarn test && yarn codecov
|
command: yarn test
|
||||||
|
|
||||||
|
# Coverage
|
||||||
|
- run:
|
||||||
|
name: Coverage
|
||||||
|
command: yarn codecov
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Common
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
.nuxt
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# Plugin
|
||||||
|
lib/plugin.js
|
29
.eslintrc.js
29
.eslintrc.js
|
@ -1,31 +1,10 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
root: true,
|
root: true,
|
||||||
// parser: 'babel-eslint',
|
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
|
parser: 'babel-eslint',
|
||||||
sourceType: 'module'
|
sourceType: 'module'
|
||||||
},
|
},
|
||||||
env: {
|
extends: [
|
||||||
browser: true,
|
'@nuxtjs'
|
||||||
node: true,
|
]
|
||||||
jest: true
|
|
||||||
},
|
|
||||||
extends: 'standard',
|
|
||||||
plugins: [
|
|
||||||
'jest',
|
|
||||||
'vue'
|
|
||||||
],
|
|
||||||
rules: {
|
|
||||||
// Allow paren-less arrow functions
|
|
||||||
'arrow-parens': 0,
|
|
||||||
// Allow async-await
|
|
||||||
'generator-star-spacing': 0,
|
|
||||||
// Allow debugger during development
|
|
||||||
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
|
|
||||||
// Do not allow console.logs etc...
|
|
||||||
'no-console': 2
|
|
||||||
},
|
|
||||||
globals: {
|
|
||||||
'jest/globals': true,
|
|
||||||
jasmine: true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,6 @@ node_modules
|
||||||
*.log*
|
*.log*
|
||||||
.nuxt
|
.nuxt
|
||||||
.vscode
|
.vscode
|
||||||
.DS_STORE
|
.DS_Store
|
||||||
coverage
|
coverage
|
||||||
_book
|
dist
|
||||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2017 Nuxt Community
|
Copyright (c) Nuxt Community
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
47
README.md
47
README.md
|
@ -1,28 +1,13 @@
|
||||||
# 📦 Axios Module
|
# 📦 Axios Module
|
||||||
|
|
||||||
> Secure and Easy <a href="https://github.com/mzabriskie/axios">Axios</a> integration with Nuxt.js.
|
[![npm version][npm-version-src]][npm-version-href]
|
||||||
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
||||||
|
[![Circle CI][circle-ci-src]][circle-ci-href]
|
||||||
|
[![Codecov][codecov-src]][codecov-href]
|
||||||
|
[![Dependencies][david-dm-src]][david-dm-href]
|
||||||
|
[![Standard JS][standard-js-src]][standard-js-href]
|
||||||
|
|
||||||
<p align="center">
|
> Secure and Easy <a href="https://github.com/mzabriskie/axios">Axios</a> integration with Nuxt.js.
|
||||||
<a href="https://david-dm.org/nuxt-community/axios-module">
|
|
||||||
<img alt="" src="https://david-dm.org/nuxt-community/axios-module/status.svg?style=flat-square">
|
|
||||||
</a>
|
|
||||||
<a href="https://standardjs.com">
|
|
||||||
<img alt="" src="https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square">
|
|
||||||
</a>
|
|
||||||
<a href="https://circleci.com/gh/nuxt-community/axios-module">
|
|
||||||
<img alt="" src="https://img.shields.io/circleci/project/github/nuxt-community/axios-module.svg?style=flat-square">
|
|
||||||
</a>
|
|
||||||
<a href="https://codecov.io/gh/nuxt-community/axios-module">
|
|
||||||
<img alt="" src="https://img.shields.io/codecov/c/github/nuxt-community/axios-module.svg?style=flat-square">
|
|
||||||
</a>
|
|
||||||
<br>
|
|
||||||
<a href="https://npmjs.com/package/@nuxtjs/axios">
|
|
||||||
<img alt="" src="https://img.shields.io/npm/v/@nuxtjs/axios/latest.svg?style=flat-square">
|
|
||||||
</a>
|
|
||||||
<a href="https://npmjs.com/package/@nuxtjs/axios">
|
|
||||||
<img alt="" src="https://img.shields.io/npm/dt/@nuxtjs/axios.svg?style=flat-square">
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
## ✅ Features
|
## ✅ Features
|
||||||
|
|
||||||
|
@ -46,4 +31,20 @@
|
||||||
|
|
||||||
## 📑 License
|
## 📑 License
|
||||||
|
|
||||||
[MIT License](./LICENSE) - Nuxt Community
|
[MIT License](./LICENSE)
|
||||||
|
|
||||||
|
Copyright (c) Nuxt Community
|
||||||
|
|
||||||
|
<!-- Badges -->
|
||||||
|
[npm-version-src]: https://img.shields.io/npm/dt/@nuxtjs/axios.svg?style=flat-square
|
||||||
|
[npm-version-href]: https://npmjs.com/package/@nuxtjs/axios
|
||||||
|
[npm-downloads-src]: https://img.shields.io/npm/v/@nuxtjs/axios/latest.svg?style=flat-square
|
||||||
|
[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/axios
|
||||||
|
[circle-ci-src]: https://img.shields.io/circleci/project/github/nuxt-community/axios-module.svg?style=flat-square
|
||||||
|
[circle-ci-href]: https://circleci.com/gh/nuxt-community/axios-module
|
||||||
|
[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/axios-module.svg?style=flat-square
|
||||||
|
[codecov-href]: https://codecov.io/gh/nuxt-community/axios-module
|
||||||
|
[david-dm-src]: https://david-dm.org/nuxt-community/axios-module/status.svg?style=flat-square
|
||||||
|
[david-dm-href]: https://david-dm.org/nuxt-community/axios-module
|
||||||
|
[standard-js-src]: https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square
|
||||||
|
[standard-js-href]: https://standardjs.com
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
'@babel/preset-env', {
|
||||||
|
targets: {
|
||||||
|
esmodules: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
module.exports = {
|
||||||
|
extends: [
|
||||||
|
'@commitlint/config-conventional'
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
module.exports = {
|
||||||
|
hooks: {
|
||||||
|
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
|
||||||
|
'pre-commit': 'yarn lint',
|
||||||
|
'pre-push': 'yarn lint'
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
module.exports = {
|
||||||
|
testEnvironment: 'node',
|
||||||
|
collectCoverage: true,
|
||||||
|
collectCoverageFrom: [
|
||||||
|
'lib/**/*.js',
|
||||||
|
'!lib/plugin.js'
|
||||||
|
],
|
||||||
|
moduleNameMapper: {
|
||||||
|
'^~/(.*)$': '<rootDir>/lib/$1',
|
||||||
|
'^~~$': '<rootDir>',
|
||||||
|
'^@@$': '<rootDir>',
|
||||||
|
'^@/(.*)$': '<rootDir>/lib/$1'
|
||||||
|
},
|
||||||
|
transform: {
|
||||||
|
'^.+\\.js$': 'babel-jest'
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ const consola = require('consola')
|
||||||
|
|
||||||
const logger = consola.withScope('nuxt:axios')
|
const logger = consola.withScope('nuxt:axios')
|
||||||
|
|
||||||
module.exports = function nuxtAxios (_moduleOptions) {
|
function axiosModule(_moduleOptions) {
|
||||||
// Combine options
|
// Combine options
|
||||||
const moduleOptions = Object.assign({}, this.options.axios, _moduleOptions)
|
const moduleOptions = Object.assign({}, this.options.axios, _moduleOptions)
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ module.exports = function nuxtAxios (_moduleOptions) {
|
||||||
|
|
||||||
// Register plugin
|
// Register plugin
|
||||||
this.addPlugin({
|
this.addPlugin({
|
||||||
src: path.resolve(__dirname, 'plugin.template.js'),
|
src: path.resolve(__dirname, 'plugin.js'),
|
||||||
fileName: 'axios.js',
|
fileName: 'axios.js',
|
||||||
options
|
options
|
||||||
})
|
})
|
||||||
|
@ -99,4 +99,5 @@ module.exports = function nuxtAxios (_moduleOptions) {
|
||||||
logger.debug(`browserBaseURL: ${options.browserBaseURL}`)
|
logger.debug(`browserBaseURL: ${options.browserBaseURL}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = axiosModule
|
||||||
module.exports.meta = require('../package.json')
|
module.exports.meta = require('../package.json')
|
||||||
|
|
56
package.json
56
package.json
|
@ -3,6 +3,9 @@
|
||||||
"version": "5.3.6",
|
"version": "5.3.6",
|
||||||
"description": "Secure and easy axios integration with Nuxt.js",
|
"description": "Secure and easy axios integration with Nuxt.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"contributors": [
|
||||||
|
"Pooya Parsa <pooya@pi0.ir>"
|
||||||
|
],
|
||||||
"main": "lib/module.js",
|
"main": "lib/module.js",
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"repository": "https://github.com/nuxt-community/axios-module",
|
"repository": "https://github.com/nuxt-community/axios-module",
|
||||||
|
@ -12,29 +15,13 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nuxt test/fixture",
|
"dev": "nuxt test/fixture",
|
||||||
"lint": "eslint lib test",
|
"lint": "eslint lib test",
|
||||||
"test": "npm run lint && jest",
|
"test": "yarn lint && jest",
|
||||||
"release": "standard-version && git push --follow-tags && npm publish",
|
"release": "yarn test && standard-version && git push --follow-tags && npm publish"
|
||||||
"prepare": "npm run test"
|
|
||||||
},
|
},
|
||||||
"eslintIgnore": [
|
|
||||||
"*.template.*"
|
|
||||||
],
|
|
||||||
"files": [
|
"files": [
|
||||||
"lib",
|
"lib",
|
||||||
"src",
|
|
||||||
"dist",
|
|
||||||
"index.d.ts"
|
"index.d.ts"
|
||||||
],
|
],
|
||||||
"jest": {
|
|
||||||
"testEnvironment": "node",
|
|
||||||
"coverageDirectory": "./coverage/",
|
|
||||||
"collectCoverage": true,
|
|
||||||
"collectCoverageFrom": [
|
|
||||||
"lib",
|
|
||||||
"test",
|
|
||||||
"!test/fixture"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxtjs/proxy": "^1.3.1",
|
"@nuxtjs/proxy": "^1.3.1",
|
||||||
"axios": "^0.18.0",
|
"axios": "^0.18.0",
|
||||||
|
@ -42,18 +29,25 @@
|
||||||
"consola": "^2.4.0"
|
"consola": "^2.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"codecov": "^3.1.0",
|
"@babel/core": "latest",
|
||||||
"eslint": "^5.13.0",
|
"@babel/preset-env": "latest",
|
||||||
"eslint-config-standard": "^12.0.0",
|
"@commitlint/cli": "latest",
|
||||||
"eslint-plugin-import": "^2.16.0",
|
"@commitlint/config-conventional": "latest",
|
||||||
"eslint-plugin-jest": "^22.2.2",
|
"@nuxtjs/eslint-config": "latest",
|
||||||
"eslint-plugin-node": "^8.0.1",
|
"babel-eslint": "latest",
|
||||||
"eslint-plugin-promise": "^4.0.1",
|
"babel-jest": "latest",
|
||||||
"eslint-plugin-standard": "^4.0.0",
|
"codecov": "latest",
|
||||||
"eslint-plugin-vue": "^5.1.0",
|
"eslint": "latest",
|
||||||
"jest": "^24.1.0",
|
"eslint-config-standard": "latest",
|
||||||
"jsdom": "^13.2.0",
|
"eslint-plugin-import": "latest",
|
||||||
"nuxt-edge": "^2.3.0-25706271.cca799c",
|
"eslint-plugin-jest": "latest",
|
||||||
"standard-version": "^4.4.0"
|
"eslint-plugin-node": "latest",
|
||||||
|
"eslint-plugin-promise": "latest",
|
||||||
|
"eslint-plugin-standard": "latest",
|
||||||
|
"eslint-plugin-vue": "latest",
|
||||||
|
"husky": "latest",
|
||||||
|
"jest": "latest",
|
||||||
|
"nuxt-edge": "latest",
|
||||||
|
"standard-version": "latest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
jest.setTimeout(60000)
|
||||||
|
|
||||||
const { Nuxt, Builder } = require('nuxt-edge')
|
const { Nuxt, Builder } = require('nuxt-edge')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const config = require('./fixture/nuxt.config')
|
const config = require('./fixture/nuxt.config')
|
||||||
|
@ -18,7 +20,7 @@ describe('axios module', () => {
|
||||||
|
|
||||||
await new Builder(nuxt).build()
|
await new Builder(nuxt).build()
|
||||||
await nuxt.listen(3000)
|
await nuxt.listen(3000)
|
||||||
}, 60000)
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
|
@ -26,10 +28,10 @@ describe('axios module', () => {
|
||||||
|
|
||||||
test('baseURL', () => {
|
test('baseURL', () => {
|
||||||
expect(addTemplate).toBeDefined()
|
expect(addTemplate).toBeDefined()
|
||||||
let call = addTemplate.mock.calls.find(args =>
|
const call = addTemplate.mock.calls.find(args =>
|
||||||
args[0].src.includes('plugin.template.js')
|
args[0].src.includes('plugin.js')
|
||||||
)
|
)
|
||||||
let options = call[0].options
|
const options = call[0].options
|
||||||
expect(options.baseURL.toString()).toBe(
|
expect(options.baseURL.toString()).toBe(
|
||||||
`http://localhost:3000/test_api`
|
`http://localhost:3000/test_api`
|
||||||
)
|
)
|
||||||
|
@ -37,7 +39,7 @@ describe('axios module', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('asyncData', async () => {
|
test('asyncData', async () => {
|
||||||
let html = (await axios.get(url('/asyncData'))).data
|
const html = (await axios.get(url('/asyncData'))).data
|
||||||
expect(html).toContain('foo/bar')
|
expect(html).toContain('foo/bar')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -65,10 +67,10 @@ describe('axios module', () => {
|
||||||
.then(h => /session-[0-9]+/.exec(h))
|
.then(h => /session-[0-9]+/.exec(h))
|
||||||
.then(m => (m && m[0] ? m[0] : null))
|
.then(m => (m && m[0] ? m[0] : null))
|
||||||
|
|
||||||
let a = await makeReq()
|
const a = await makeReq()
|
||||||
let b = await makeReq(true)
|
const b = await makeReq(true)
|
||||||
let c = await makeReq()
|
const c = await makeReq()
|
||||||
let d = await makeReq(true)
|
const d = await makeReq(true)
|
||||||
|
|
||||||
expect(a).toBeNull()
|
expect(a).toBeNull()
|
||||||
expect(b).not.toBeNull()
|
expect(b).not.toBeNull()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
path: '/test_api',
|
path: '/test_api',
|
||||||
handler (req, res) {
|
handler(req, res) {
|
||||||
res.end(JSON.stringify({
|
res.end(JSON.stringify({
|
||||||
url: req.url,
|
url: req.url,
|
||||||
method: req.method
|
method: req.method
|
||||||
|
|
|
@ -7,7 +7,9 @@ module.exports = {
|
||||||
render: {
|
render: {
|
||||||
resourceHints: false
|
resourceHints: false
|
||||||
},
|
},
|
||||||
modules: ['@@'],
|
modules: [
|
||||||
|
{ handler: require('../../') }
|
||||||
|
],
|
||||||
serverMiddleware: ['~/api.js'],
|
serverMiddleware: ['~/api.js'],
|
||||||
axios: {
|
axios: {
|
||||||
prefix: `/test_api`,
|
prefix: `/test_api`,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
export default function ({ $axios, redirect }) {
|
export default function ({ $axios, redirect }) {
|
||||||
$axios.onRequest(config => {
|
$axios.onRequest((config) => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('SPY: ' + config.url)
|
console.log('SPY: ' + config.url)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export default {
|
export default {
|
||||||
actions: {
|
actions: {
|
||||||
nuxtServerInit ({ commit }, ctx) {
|
nuxtServerInit({ commit }, ctx) {
|
||||||
if (!ctx.$axios) {
|
if (!ctx.$axios) {
|
||||||
throw new Error('$axios is not defined!')
|
throw new Error('$axios is not defined!')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue