Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create new https.Agent() within axios.init() #31

Closed
unr opened this issue Sep 18, 2017 · 4 comments
Closed

Cannot create new https.Agent() within axios.init() #31

unr opened this issue Sep 18, 2017 · 4 comments

Comments

@unr
Copy link

unr commented Sep 18, 2017

When using the axios.init() function within nuxt.config.js, creating a new https.Agent() is quite difficult.

Importing https to be used constantly returns https is undefined.

const https = require('https');

axios: {
	init(axios, context) {
		axios.defaults.httpsAgent = new https.Agent({ rejectUnauthorized: false });
	},
},

https will be undefined, and fail.

Importing https within the axios.init() callback also fails.

This question is available on Nuxt.js community (#c31)
@pi0
Copy link
Member

pi0 commented Jan 28, 2018

Please see the newer approach using 5.x. Using nuxt plugins, you can easily achive this:

plugins/axios.js

import https from 'https'

export default({ axios }) {
  axios.defaults.httpsAgent = new https.Agent({ rejectUnauthorized: false })
}

https://github.com/nuxt-community/axios-module#extending-axios

@pi0 pi0 closed this as completed Jan 28, 2018
@alanaasmaa
Copy link

I had same issue and i tried the solution here but it didn't work for me.

What worked for me was environment variable NODE_TLS_REJECT_UNAUTHORIZED="0"
Maybe something we should implement into nuxt.js dev mode?

Also i think the variable should be $axios not axios.

@laurentdebricon
Copy link

laurentdebricon commented Jul 31, 2019

Please see the newer approach using 5.x. Using nuxt plugins, you can easily achive this:

plugins/axios.js

import https from 'https'

export default({ axios }) {
  axios.defaults.httpsAgent = new https.Agent({ rejectUnauthorized: false })
}

https://github.com/nuxt-community/axios-module#extending-axios

Thank you, it works for me.
The solution is indeed with $axios.

@AntoninSlejska
Copy link

Little update:

plugins/axios.js

import https from 'https'

export default function({ $axios }) {
  $axios.defaults.httpsAgent = new https.Agent({ rejectUnauthorized: false })
}

See: https://axios.nuxtjs.org/extend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants