mirror of https://github.com/sundowndev/http.git
fix: use local version of ky-universal (#111)
parent
4152f874a1
commit
e7cb647047
|
@ -0,0 +1 @@
|
||||||
|
export { default } from 'ky'
|
|
@ -0,0 +1,9 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,32 @@
|
||||||
|
const fetch = require('node-fetch')
|
||||||
|
const AbortController = require('abort-controller')
|
||||||
|
|
||||||
|
const TEN_MEGABYTES = 1000 * 1000 * 10
|
||||||
|
|
||||||
|
if (!global.fetch) {
|
||||||
|
global.fetch = (url, options) => fetch(url, { highWaterMark: TEN_MEGABYTES, ...options })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!global.Headers) {
|
||||||
|
global.Headers = fetch.Headers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!global.Request) {
|
||||||
|
global.Request = fetch.Request
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!global.Response) {
|
||||||
|
global.Response = fetch.Response
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!global.AbortController) {
|
||||||
|
global.AbortController = AbortController
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!global.ReadableStream) {
|
||||||
|
try {
|
||||||
|
global.ReadableStream = require('web-streams-polyfill/ponyfill/es2018')
|
||||||
|
} catch (_) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = require('ky/umd')
|
|
@ -1,6 +1,5 @@
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const consola = require('consola')
|
const consola = require('consola')
|
||||||
const semver = require('semver')
|
|
||||||
|
|
||||||
const logger = consola.withScope('nuxt:http')
|
const logger = consola.withScope('nuxt:http')
|
||||||
|
|
||||||
|
@ -119,16 +118,13 @@ function httpModule (_moduleOptions) {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add `ky` to build.transpile
|
// Alias ky-universal
|
||||||
this.options.build = this.options.build || {}
|
this.options.alias['ky-universal'] = path.resolve(__dirname, '../ky-universal')
|
||||||
|
|
||||||
|
// Transpile ky and ky-universal
|
||||||
this.options.build.transpile = this.options.build.transpile || {}
|
this.options.build.transpile = this.options.build.transpile || {}
|
||||||
// transpile only for non-modern build
|
this.options.build.transpile.push('ky')
|
||||||
/* istanbul ignore next */
|
this.options.build.transpile.push('@nuxt/http')
|
||||||
if (semver.gte(semver.coerce(this.nuxt.constructor.version), '2.9.0')) {
|
|
||||||
this.options.build.transpile.push(({ isLegacy }) => isLegacy && 'ky')
|
|
||||||
} else {
|
|
||||||
this.options.build.transpile.push('ky')
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set _HTTP_BASE_URL_ for dynamic SSR baseURL
|
// Set _HTTP_BASE_URL_ for dynamic SSR baseURL
|
||||||
process.env._HTTP_BASE_URL_ = options.baseURL
|
process.env._HTTP_BASE_URL_ = options.baseURL
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import KY from 'ky-universal'
|
|
||||||
import defu from 'defu'
|
import defu from 'defu'
|
||||||
|
|
||||||
|
const KY = process.server ? require('ky-universal/node') : require('ky-universal/browser').default
|
||||||
|
|
||||||
class HTTP {
|
class HTTP {
|
||||||
constructor(defaults, ky = KY) {
|
constructor(defaults, ky = KY) {
|
||||||
this._defaults = {
|
this._defaults = {
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"types": "types/index.d.ts",
|
"types": "types/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"lib",
|
"lib",
|
||||||
|
"ky-universal",
|
||||||
"types/*.d.ts"
|
"types/*.d.ts"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -19,10 +20,11 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxtjs/proxy": "^2.0.0",
|
"@nuxtjs/proxy": "^2.0.0",
|
||||||
|
"abort-controller": "^3.0.0",
|
||||||
"consola": "^2.12.2",
|
"consola": "^2.12.2",
|
||||||
"ky": "^0.20.0",
|
"ky": "^0.20.0",
|
||||||
"ky-universal": "^0.7.0",
|
"node-fetch": "^2.6.0",
|
||||||
"semver": "^7.3.2"
|
"web-streams-polyfill": "^2.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "latest",
|
"@babel/core": "latest",
|
||||||
|
|
Loading…
Reference in New Issue