Reputation: 151
API Usage in getInitialsProps
but throwing error error connect ECONNREFUSED 127.0.0.1:443
full url: http://ingress-nginx-controller.ingress-nginx.svc.cluster.local/api/users/currentuser
But if I called https://ticketing.dev/api/users/currentuser
directly from the browser then it returned the expected response.
PS C:\Users\sajee> kubectl get namespace
NAME STATUS AGE
default Active 3d16h
ingress-nginx Active 3d15h
kube-node-lease Active 3d16h
kube-public Active 3d16h
kube-system Active 3d16h
PS C:\Users\sajee> kubectl get services -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer 10.96.242.223 localhost 80:31220/TCP,443:30164/TCP 3d15h
ingress-nginx-controller-admission ClusterIP 10.109.183.213 <none> 443/TCP 3d15h
PS C:\Users\sajee>
Upvotes: 0
Views: 698
Reputation: 11
Home.getInitialProps = async ({ req }) => {
if (typeof window === "undefined") {
const { data } = await axios.get("http://ingress-nginx-controller.ingress-nginx.svc.cluster.local/api/users/currentuser",
{
headers: req.headers,
}
);
return data;
} else {
// we are on the browser!
const { data } = await axios.get("/api/users/currentuser");
return data;
}
return {};
};
Try to pass with req props and sent headers with req.headers. Right now you are working with auth service and client service.your ingress nginx server try to find route in client service initially there are no routes or api endpoint not found.if you hard refresh your browser then the request goes to your auth service and fetch data.
Upvotes: 1