简体   繁体   中英

How make fetch requests on API with private ip?

I am working on project with microservices, and i have some issues. I have a ReactJS frontend, and a ASP.NET API, and i am working on docker/kubernetes environment. I try to fetch data on my front from API like this :

    const https = require("https");
    const agent = new https.Agent({
        mode: "cors",
        method: 'GET',
        rejectUnauthorized: false
    })
    return fetch(hostApi1 +'/api/Weather/Index', { agent })

hostapi1= https://10.0.96.227:5001 The Frontend have a public ip, and the api a private ip.

But the console return this error :

FetchWeather.tsx:130 GET https://10.0.96.227:5001/api/Weather/Index net::ERR_CONNECTION_TIMED_OUT

But when i try this from the front container :

curl -k https://10.0.96.227:5001/api/Weather/Index

I obtain a good response with my data.

So there some specifics to add in my request for fetch data on API with private IP ? (when i add a public ip for my api it works, but this this not the aim)

Thanks for any help.

Your ReactJS frontend is running in user's browser. So you need to connect to backend using external IP. You cannot use private cluster ip from outside the cluster.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM