Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

axiosist

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axiosist - npm Package Compare versions

Comparing version 0.4.0 to 0.5.1

46

index.js

@@ -1,2 +0,7 @@

'use strict'
/** @typedef {import('net').AddressInfo} AddressInfo */
/** @typedef {import('http').Server} Server */
/** @typedef {import('http').IncomingMessage} IncomingMessage */
/** @typedef {import('http').ServerResponse} ServerResponse */
/** @typedef {import('axios').AxiosAdapter} AxiosAdapter */
/** @typedef {import('axios').AxiosInstance} AxiosInstance */

@@ -7,6 +12,27 @@ const http = require('http')

const axios = require('axios').default
const defaultAdapter = axios.defaults.adapter
const defaultAdapter = /** @type {AxiosAdapter} */(axios.defaults.adapter)
/**
* @callback RequestListener
* @param {IncomingMessage} request
* @param {ServerResponse} response
*/
/** @typedef {RequestListener | Server} Handler */
/**
* Create the adapter of the request callback, used for your own axios instance.
* ```
* axiosist(callback)
* ```
* is equal to
* ```
* axios.create({ adapter: axiosist.createAdapter(callback) })
* ```
*
* @param {Handler} handler A handler for axiosist, may be a request listener or a http server.
* @returns {AxiosAdapter} The axios adapter would used in adapter options of axios.
*/
const createAdapter = handler => config => {
const urlObject = url.parse(config.url)
const urlObject = url.parse(config.url || '')

@@ -36,3 +62,4 @@ // Forcely set protocol to HTTP

}).then(() => {
urlObject.port = server.address().port
const address = /** @type {AddressInfo} */(server.address())
urlObject.port = address.port.toString()
config.url = url.format(urlObject)

@@ -55,2 +82,8 @@ return defaultAdapter(config)

/**
* Create an axios instance with adapter of the request callback, and treat all HTTP statuses as fulfilled.
*
* @param {Handler} handler A handler, may be a request listener or a http server.
* @returns {AxiosInstance} The axios instance would use for test.
*/
const axiosist = handler => {

@@ -64,4 +97,3 @@ return axios.create({

exports = module.exports = axiosist
exports.default = axiosist
exports.createAdapter = createAdapter
module.exports = axiosist
module.exports.createAdapter = createAdapter

5

package.json
{
"name": "axiosist",
"version": "0.4.0",
"version": "0.5.1",
"description": "Convert node.js request handler to axios adapter",

@@ -22,2 +22,5 @@ "main": "index.js",

],
"files": [
"index.js"
],
"author": "George Cheng <Gerhut@GMail.com>",

@@ -24,0 +27,0 @@ "license": "MIT",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc