CaptEmulation / clash-of-clans-api

:star::star::star: Clash of Clans :rage1: API NodeJS helper
MIT License
64 stars 25 forks source link

Proxy support #7

Closed danielegli closed 7 years ago

danielegli commented 7 years ago

Since the coc API is IP restricted per token, it would be nice to have a proxy option for the web calls so that I could use a third-party service to run my calls through.

CaptEmulation commented 7 years ago

This module is intended to be run on the server side on a fixed IP. However, you can try out https://github.com/CaptEmulation/coc-api-proxy for a dedicated CoC API proxy

ionutale commented 7 years ago

Waw captemulation you are fast on replay My compliments sir

Il giorno 19 mag 2017, alle ore 22:44, John Dean notifications@github.com ha scritto:

This module is intended to be run on the server side on a fixed IP. However, you can try out https://github.com/CaptEmulation/coc-api-proxy for a dedicated CoC API proxy

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

CaptEmulation commented 7 years ago

Thanks. Going to close this issue. Raise an issue at https://github.com/CaptEmulation/coc-api-proxy/issues if you have any problems

danielegli commented 7 years ago

Yes, very quick indeed. Okay, thanks for the link and the work on this one (it was easy to use and worked well minus the proxy bit)

CaptEmulation commented 7 years ago

You were able to run this module in the browser? I actually never tried that.

danielegli commented 7 years ago

I was running a local express server and using the API on my backend to get clan data. I wanted to deploy to a free heroku dyno for small clan usage, but the heroku dyno changes IPs constantly so my token is always invalidated. There are proxy addons in heroku but I need a way to set the proxy option for the coc request. I'm not terribly familiar with the http requests in node, but I think I'll have to rip apart the code a bit and try to get the proxy option working (or just rewrite my own requests I guess)

CaptEmulation commented 7 years ago

ah OK. This is an known problem with the Clash of Clans API. They (Supercell) require a fixed static IP.

danielegli commented 7 years ago

I think I stumbled onto a quick and easy solution. You're using request-promise, built off http which respects the HTTP_PROXY env variable. Therefore this line of code:

process.env['HTTP_PROXY'] = process.env.QUOTAGUARDSTATIC_URL;

solves the problem and routes my app's outbound requests through the heroku addon proxy.

CaptEmulation commented 7 years ago

nice! Going to reopen this to add some text to the readme to cover this. PRs accepted

danielegli commented 7 years ago

Hmm, I'm not sure how that constructor works exactly sorry. I imagine the best solution though would be to add another option to clashApi and then set it inside that constructor though.

CaptEmulation commented 7 years ago

Check out v0.4.0 of this module which includes a new request option for setting request options.

danielegli commented 7 years ago

Nice work and thanks. My little side project is chugging away nicely now

CaptEmulation commented 7 years ago
import clashApi from 'clash-of-clans-api';
let client = clashApi({
  token: myToken,
  request: {
    proxy: process.env.QUOTAGUARDSTATIC_URL,
  },
});

See request options for the full list of supported request options

PrittSpadeLord commented 6 years ago

danielegli, thank you so much, that simple fix was all that was needed to fix my two month long problem. Hats off to you sir!

danielegli commented 6 years ago

:) happy building

CaptEmulation commented 6 years ago

Good luck with your application :-)

CaptEmulation commented 6 years ago

Question @PrittSpadeLord-- did you use the HTTP_PROXY env var or the request: { proxy: } } option to resolve your issue? Just wondering if the latter option works correctly.

PrittSpadeLord commented 4 years ago

@CaptEmulation Sorry for the extreme delay in responding, I had used:

process.env['HTTP_PROXY'] = process.env.QUOTAGUARDSTATIC_URL;

CaptEmulation commented 4 years ago

No problem :+1: Thanks!