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
NextJS getInitialProps and proxy of my company #8541
Comments
Seems like your internal network is just not allowing connecting to the specified url 🤔 The specific API is not down (just checked) 🤔 |
It happend only on builded page. If i run request to this api from browser console - i get response. |
That's very strange 🤔 Maybe there's network policies, but I can't imagine any company being that strict. |
@timneutkens in one of the links, that i write in topic, described similar behavior. Like nextjs or something inside nextjs trying to check something and crash and thats why it happend. It resolved with "update update-check to 1.4", but... So, problem should be somewhere inside (And ofcourse in proxy). Maybe i need to do something with update-check, i dont understand... |
@VadimGorbenko sounds like you're on a really old version of Next.js, can you try to |
@timneutkens I have fresh version - 9.0.0 |
That does not include update-check |
Ye, i write that message as example, that similiar behavior not new and problem was in update-check. I am dont know where problem is now. |
Still actual |
We can't really do anything here, there is no reproduction. |
I'm closing the issue because I can't reproduce it and the lesson is working as intended, if the issue persists please provide a reproduction 🙏 |
Hello @VadimGorbenko! I confirm that the issue is related with the proxy. I have the similar problem and I was not able to solve that. Below are several ways you could try for yourself. Perhaps you'll be more lucky. Use axios instead of unfetch. Thus you will be able to control the proxy settings. Here you have the two options:
Index.getInitialProps = async function() {
const config = {
proxy: {
host: '127.0.0.1',
port: 9000,
auth: {
username: 'mikeymike',
password: 'rapunz3l'
}
}
}
const res = await axios.get('https://api.tvmaze.com/search/shows?q=batman', config);
const data = await res.json();
console.log(`Show data fetched. Count: ${data.length}`);
return {
shows: data.map(entry => entry.show)
};
};
import HttpsProxyAgent from 'https-proxy-agent';
...
Index.getInitialProps = async function() {
const config = {
httpsAgent: new HttpsProxyAgent(process.env.https_proxy)
}
const res = await axios.get('https://api.tvmaze.com/search/shows?q=batman', config);
const data = await res.json();
console.log(`Show data fetched. Count: ${data.length}`);
return {
shows: data.map(entry => entry.show)
};
}; For this to work you should fix webpack config slightly. Create module.exports = {
webpack: (config, { isServer }) => {
// Fixes npm packages that depend on `fs` module
if (!isServer) {
config.node = {
net: 'empty',
tls: 'empty'
}
}
return config
}
} |
Hi, I had stacked as above but solved by following @kbychkov code, so I show the code for an example. import Layout from '../components/MyLayout'
import Link from 'next/link'
import fetch from 'isomorphic-unfetch'
import HttpsProxyAgent from 'https-proxy-agent'
import axios from 'axios'
const Index = props => (
<Layout>
<h1>Batman TV Shows</h1>
<ul>
{props.shows.map(show => (
<li key={show.id}>
<Link href="/show/[id]" as={`/show/${show.id}`}>
<a>{show.name}</a>
</Link>
</li>
))}
</ul>
</Layout>
)
Index.getInitialProps = async function() {
const config = {
httpsAgent: new HttpsProxyAgent(process.env.npm_config_https_proxy)
}
const res = await axios.get('https://api.tvmaze.com/search/shows?q=batman', config);
const data = await res.data;
console.log(`Show data fetched. Count: ${data.length}`);
return {
shows: data.map(entry => entry.show)
};
}
export default Index |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Hello everyone!
Help required.
I am now on NextJS learning guid. Lesson №6 - fetching data. Step №3.
When i do all steps in lesson, where we first time trying to fetch data from external public api in getInitialProps(https://api.tvmaze.com/search/shows?q=batman) and type in terminal "npm start dev", dev server is started on localhost:3000, but i get an error:
I spend alot of time in search how to solve it and find this - marked as duplicate of next one but it seems that its dosnt work for me.
I have .npmrc file with next config:
both are http.
I start feel myself a little bit silly because i still dont understand how to fix it :c
System:
OS: Windows 7
Binaries:
Node: 8.10.0
npm: 6.7.0
Browsers:
Firefox: 68.0.2,
IE: 11,
P.s. i wanted write this in spectrum chat, but i have crashed websocket connection and my FF trying to reconnect in loop.
The text was updated successfully, but these errors were encountered: