I have a very simple use case and I can't seem to find a way to do it.
My application has an app part (angular) and an api part (nodejs). From the UI, although I call the api as /api/*, the api server itself does not have the /api prefix. Because of this, I need to rewrite any request for /api to /.
In the development environment, my angular application simply has a proxy configuration which does the rewriting:
{
"/api/*": {
"target": "http://localhost:3000",
"pathRewrite": {
"^/api/": ""
},
"secure": false,
"logLevel": "debug"
}
}
So, for the production environment, I need to configure the GCP load balancer for the following scenarios:
| incoming path | backend-service | path rewrite |
|---|---|---|
| / | ui-backend-service | (N/A) |
| /app | ui-backend-servicw | (N/A) |
| /api | api-backend-service | / |
While I am able to configure the simple Routing rules for mapping the host and path to the ui-backend-service, it looks really difficult to rewrite url for /api.
Any example that I could find for URL rewriting shows the Classic Load Balancing, which does not seem to be applicable anymore.
I tried modifying the Advanced host and path rules, but it tells me that I can either provide pathRules or routeRules, not both.
I cannot create a separate rule, because the host (which is * in my case) cannot be used more than once.
I don't want to setup an nginx on my api server just for this. Is there another way to do it?