Requests Fail from getServerSideProps due to Proxy (400 Bad Request) #47382
Unanswered
adrienclay36
asked this question in
Help
Replies: 1 comment 2 replies
-
So Could you try with what they show in this article? https://www.scrapingbee.com/blog/proxy-node-fetch/ In Node 16, Next.js polyfills fetch with node-fetch, server side, so you'd just need to add the https-proxy-agent library. If you make a script that just uses fetch server side, does it work? You'd need Node 18 at least, to get native fetch available, but I think it might be worth removing Next.js from the equation first, and see if you can hit your Proxy at all through server side fetching, aka with a Node.js script. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
At my company we work behind a proxy and develop applications to be used on a private network.
When I try to use either fetch or Axios to get data external to the application (as in, I'm not using NextJS Api routes, I'm getting data from other servers) I am getting an http proxy request error in both scenarios. It's always a 400 error for both public api's of any kind and my dotnet API server that's running on localhost. It appears it only happens in development, not when the app is deployed.
What's odd to me is that this doesn't happen when executing requests client side with either fetch or axios. Those work just fine. I really want to incorporate data availability on load with NextJS for this application, but I suppose I could drive forward with all client side data fetching only if I can't get this to work. it wouldn't be a huge deal but defeats at least 1/3 of the purpose of me using NextJS for this project. I'm mostly in it for the file routing, but ultimately the SSR was a huge draw for me.
I've tried multiple approaches so far (For context, this all would be taking place inside of getServerSideProps)
This happens for AXIOS and FETCH, it makes no difference.
This method doesn't work, I'm not sure why, doesn't work with or without auth settings.
One interesting thing about this is that if I DONT include this, I can see in the axios error that it already has the proxy as "mycompany.proxy.com"
Same error occurs here, no changes in output. Still a 400 bad request error.
With this, I get the error ECONNRESET, not sure what this means other than I read that it means the target url shut down the request prematurely for some reason.
The only solution that works, and it only works for localhost, not public API's
I am at a complete loss as to what to do here. Nothing is working and I can't find anything online that points to anything I feel like I haven't seen already. I feel like I've tried everything under the sun.
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions