How to use a proxy to obtain a static IP for my Node.js application?

19 Views Asked by At

I am consuming the Brawl Stars API, and to access it, a key tied to the IP address is required. So far, so good when I ran my application locally. However, when I deploy it, I don't have access to that IP to put in the key. I've been trying to solve this for a few months now, tried literally everything, and after weeks of research on how to fix this, I came across someone on GitHub who said they solved it using a proxy. They provided the proxy code in their repository. However, another problem arises: I've never used a proxy before. But as it's the only way to make this work, I'm trying to understand how it works, but it's been difficult to find information about it.

My questions are: how can I use this proxy to get a static IP for my site? When I upload this proxy to the server, won't it have a dynamic IP? (This question may seem a bit silly, but I'm really lost). Where do I find the 'proxy IP' to put in the API key?

The repository I mentioned is this one: https://github.com/DEV-DIBSTER/Brawl-Stars-Proxy

Part where I consume the proxy (Example)

app.get("/", async (req, res) => {
    try {
        // Proxy URL http://localhost:8000
        const response = await axios.get("http://localhost:8000/v1/players/%232LY8J89CV", {
            headers: {
                "Accept": "application/json",
                "Authorization": `Bearer ${apiKey}`,
            }
        });
        return res.json(response.data);
    } catch (error) {
        if (error.response) {
            const statusCode = error.response.status;
            let errorMessage = "Unknown error";
            let errorDetail = {};

            if (statusCode === 403) {
                errorMessage = "Access denied. Verify your credentials or API token.";
            } else if (statusCode === 404) {
                errorMessage = "Resource not found.";
            } else if (statusCode === 429) {
                errorMessage = "Request has been limited due to excessive requests.";
            } else if (statusCode === 500) {
                errorMessage = "Internal server error.";
            } else if (statusCode === 503) {
                errorMessage = "Service temporarily unavailable due to maintenance.";
            }

            return res.status(statusCode).json({
                error: errorMessage,
                detail: error.response.data
            });
        } else {
            console.error("Error making request to Brawl Stars API:", error.message);
            return res.status(500).json({
                error: "Internal server error",
                detail: error.message
            });
        }
    }
});

Thank you for any guidance or suggestion to resolve this issue.

I've tried a bit of everything, from creating VM instances with static IPs to the most different ideas I found online. Note: I don't have a budget:(

0

There are 0 best solutions below