Closed kaf-lamed-beyt closed 8 months ago
Can you check if the proxy is working or not from you local system?
Hi @Rishikant181,
It isn't working locally. It throws the internal server error.
It only works when I do not use the Proxy URL
Is the proxy working and reachable?
I don't think so. It doesn't work in prod. Only locally. And that's if I do not add the proxyUrl
arg
Then it seems like it's something to do with the proxy server you are using. Can you try it with some other proxy?
Oh! What alternatives would you recommend?
And that's if I do not add the
proxyUrl
arg
What proxy were you using earlier?
And that's if I do not add the
proxyUrl
argWhat proxy were you using earlier?
I was using my app's base URL withe API route appended like so:
const retweetInstance = new Rettiwt({
proxyUrl: new URL(`${process.env.NEXT_PUBLIC_PROXY_URL}/api/tweet`),
});
I even tried setting the proxy in package.json like so:
"proxy": {
"/api/tweet": {
"target": "https://api.twitter.com/1.1",
"changeOrigin": true
}
},
Now, it throws the 429 error when I checked the stack trace from my logs. I'm going to try this http-proxy-middleware
package and let you know if it works or not.
I was using my app's base URL withe API route appended like so
Ahh I see, that's the issue. You misunderstood the proxyUrl argument.
The proxyUrl arguments is actually used to set the URL of the proxy server, which will be making HTTPS requests to Twitter on your behalf. You see, Twitter Web App API block requests from cloud service providers. In order to bypass this restriction, another publicly available computer is used, through which your requests to Twitter will be routed, which will fool Twitter into thinking that the HTTP requests come from a 'normal' computer and not a cloud service provider's computer. This is called proxy-ing. You can read more about it here.
In this case, you have to use a separate proxy server (there are paid as well as freely available ones on the internet, a google search will help). After choosing a proxy server, you pass that proxy server's full url to proxyUrl arg.
Aha! I see.
Thank you for this detailed clarification. Quick question though... the target API endpoint is: "https://api.twitter.com/1.1", yeah?
Yes, but you need not concern yourself with that. Everything is handle by rettiwt-api internally and all you need to do is use a proxy server. For example, if we are using a publicly available, free proxy server with IP address xxx.xxx.xxx.xxx with port yyyy, the configuration will be:
const rettiwt = new Rettiwt({ proxyUrl: new URL('http://xxx.xxx.xxx.xxx:yyyy') })
That's all is needed.
Instead of proxyUrl, you may use just authProxyUrl as described here
If authProxyUrl doesn't help, then you may need to use a full proxy with proxyUrl.
Niceee!! I'll try getting a free proxy url and let you know the outcome
@Rishikant181, In the meantime... can you recommend where I can get proxy URLs? I tried using one from this place, but I got a refused connection error
cause: Error: connect ECONNREFUSED 36.89.129.213:5678
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '36.89.129.213',
port: 5678
},
Try multiple, whichever one works for you (that's how even I do it :P)
I found one after several trials! Thanks for your help.
For anyone who might run into this same issue in the future, here's a repo with an exhaustive (I think) list of proxy servers.
Glad it worked out!
I'm using this package in my Next.js App, specifically as an API route.
Locally, everything works fine, but when I deploy to Vercel... I keep getting 500: Internal server error. So I decided to include the proxyUrl parameter... But the error still persists.
Here's what my API route looks like:
And here's the error log from Vercel.