Skip to content

Commit

Permalink
fixup! Logging with baseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
tenorok committed Mar 6, 2020
1 parent ac2ede8 commit ffc4ed1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
@@ -1,13 +1,13 @@
'use strict'

var path = require('path');
var { URL } = require('url')
var axios = require('axios')
var buildURL = require('axios/lib/helpers/buildURL')
var axiosDebug = require('debug')('axios')

const getURL = (config) => {
const url = path.join(config.baseURL || '', config.url)
return buildURL(url, config.params, config.paramsSerializer)
const fullURL = new URL(config.url, config.baseURL)
return buildURL(fullURL.toString(), config.params, config.paramsSerializer)
}

var options = {
Expand Down
21 changes: 21 additions & 0 deletions test.js
Expand Up @@ -206,6 +206,27 @@ it('should add custom debug logger to axios instance', () => {
})
})

it('should logging request with baseURL', async () => {
return axios.create()({
method: 'BAZ',
baseURL: 'http://example.com/',
url: '/path',
adapter: config => Promise.resolve({
status: 200,
statusText: 'QUX',
config
})
}).then(() => {
debug.log.should.be.calledTwice()
debug.log.firstCall.should.be.calledWithExactly(
'BAZ http://example.com/path'
)
debug.log.secondCall.should.be.calledWithExactly(
'200 QUX', '(BAZ http://example.com/path)'
)
})
})

it('should be able to set format of response & response logging', () => {
const requestLogger = sinon.spy((debug, config) => debug(config.method.toUpperCase()))
const responseLogger = sinon.spy((debug, response) => debug(response.statusText.toUpperCase()))
Expand Down

0 comments on commit ffc4ed1

Please sign in to comment.