Thought I’d post an update here in case this is of interest. For context, all of this is inside a Kubernetes (GKE), so nginx refers to an nginx ingress controller.
1. In the beginning I put an nginx which simply maps the Growthbook’s app doman (e.g.
my-gb.com) to service’s port 3000, and Growthbook’s API origin (e.g.
my-gb.com/custom-api) into the service’s port 3100.
◦ This does not work. The landing page loads, but calls to the custom-api/auth/refresh fails with authorisation token not found.
◦ I have no knowledge of how next.js works, but I suspect any call to <app-domain>/<path> needs to be authenticated, except the auth/refresh
2. Knowing the problem in 1, my next attempt is to get nginx to rewrite the URLs. So if the browser sends (
my-gb.com/custom-api), I need to get nginx to map it to the service’s port 3100,
and remove the
custom-api
prefix. This can be done with nginx’s _
rewrite-target_
annotation. Due to the complexity of the regex, I try to keep things simple by splitting the application and the api to be handled by two separate nginx ingress controllers.
a. This seem to work, at least I’ve tried browsing around and there’s no error in the browser’s console so far
b. It continues to work after I remove all the allow CORS headers from my ingress controller
c. Having said that I’m not sure if this would work for all cases, since now I’m at the mercy of the regex replacement.