nhays89
nhays89

Reputation: 13

is it possible to map all requests to a route under a certain path i.e '/api/**' to a different app in pcf?

As the title suggests, I have a frontend app and a backend api. Each with their own manifest running in pcf in their own containers. They are on the same origin. I want to route all api requests to the backend api, and every other request to the frontend app. This is currently possible via map-route cmd in pcf cli or app manager. For every endpoint I have in my backend api, I map the endpoint to a route 'api/path1', 'api/path2', 'api/path3', 'api/path4', 'api/path5', api/path6', 'api/path7', 'api/path8', 'api/path9'................ except the only problem is I have to list every single endpoint I want mapped. Wildcards are not supported..at least I haven't been able to get them to work. Any ideas?

Upvotes: 1

Views: 696

Answers (1)

Daniel Mikusa
Daniel Mikusa

Reputation: 15051

For every endpoint I have in my backend api, I map the endpoint to a route 'api/path1', 'api/path2', 'api/path3', 'api/path4', 'api/path5', api/path6', 'api/path7', 'api/path8', 'api/path9'

If everything under /api/ goes to your backend app, then it's not necessary to map individual paths like this. It should be sufficient to map /api/ to your backend app, and every request that starts with /api/ will go to your backend app.

The key is that everything under /api/ goes to the backend app. If you wanted to have /api/v1, /api/v2, /api/v3 and /api/v4 to go to backend and /api/something_else to go to another app then it would be more complicated because they all start with /api/ and then you'd have to add individual routes in CF.

Wildcards are not supported..at least I haven't been able to get them to work.

Correct. There is no specific wildcard character, but the match is basically a "starts with" match. If the path for a request starts with the path you add to your route, then it will match.

Ex: a route of https://www.example.com/path1 matches https://www.example.com/path1, https://www.example.com/path1/subpath and even https://www.example.com/path1/sub/sub/sub/sub/path because they all start with /path1.

See "Create an HTTP Route with a Path" here for more details.

https://docs.cloudfoundry.org/devguide/deploy-apps/routes-domains.html#create-route

Upvotes: 1

Related Questions