Comparing version 0.8.0 to 0.9.0
21
index.js
@@ -25,2 +25,11 @@ /** | ||
/** | ||
* @param {string} urlString the url to tell. | ||
* @returns {boolean} whether the url is absolute url. | ||
*/ | ||
const isAbsoluteUrl = (urlString) => { | ||
const url = new URL(urlString, 'http://axiosist/') | ||
return url.host !== 'axiosist' | ||
} | ||
/** | ||
* @param {Handler} handler A handler for axiosist, may be a request listener or a http server. | ||
@@ -30,3 +39,4 @@ * @returns {AxiosAdapter} The axios adapter would used in adapter options of axios. | ||
const createAdapter = handler => config => new Promise((resolve, reject) => { | ||
const url = new URL(config.url || '', 'http://axiosist/') | ||
const urlField = isAbsoluteUrl(config.url || '') ? 'url' : 'baseURL' | ||
const url = new URL(config[urlField] || '', 'http://axiosist/') | ||
@@ -36,7 +46,5 @@ // Forcely set protocol to HTTP | ||
const host = url.host | ||
url.host = '127.0.0.1' | ||
// Apply original host to request header | ||
if (host !== 'axiosist' && config.headers.host == null) { | ||
config.headers.host = host | ||
if (url.host !== 'axiosist' && config.headers.host == null) { | ||
config.headers.host = url.host | ||
} | ||
@@ -55,4 +63,5 @@ | ||
const address = /** @type {AddressInfo} */(server.address()) | ||
url.host = '127.0.0.1' | ||
url.port = address.port.toString() | ||
config.url = url.toString() | ||
config[urlField] = url.toString() | ||
return defaultAdapter(config) | ||
@@ -59,0 +68,0 @@ }) |
{ | ||
"name": "axiosist", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "Convert node.js request handler to axios adapter", | ||
@@ -37,3 +37,3 @@ "main": "index.js", | ||
"@types/node": ">=10.13.0", | ||
"axios": "0.19.0" | ||
"axios": "^0.19.1" | ||
}, | ||
@@ -40,0 +40,0 @@ "devDependencies": { |
8526
83
+ Addedaxios@0.19.2(transitive)
- Removedaxios@0.19.0(transitive)
- Removedis-buffer@2.0.5(transitive)
Updatedaxios@^0.19.1