How to make an Azure Container App available at a path rather than only a domain?

enthusiastic 0 Reputation points
2023-09-07T17:53:29.24+00:00

I am implementing both a web client and API deployed and running as Azure Container Apps. One of the features available to me is to use custom domains with deployed container apps. I need to have the client available at the domain level and the API available at the path level. For example: If the client is at app.example.com then the API would be at app.example.com/api. It appears that doing that might be possible with Azure API Management, but my use case is small and that seems like an expensive service since this is the only feature I am needing.

Is it possible to set up a container app to be available at a path as I am requesting? If so, how can I accomplish this?

Thank you!

Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
415 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Deepanshukatara-6769 9,190 Reputation points
    2023-09-08T05:38:54.3+00:00

    Hope you are doing good!

    Azure Container Apps (formerly known as Azure Web App for Containers) primarily maps web applications to their root domains, and it doesn't offer built-in support for path-based routing within the app service itself. To achieve path-based routing like you described (e.g., having your client at app.example.com and your API at app.example.com/api), you typically need to use a reverse proxy or an API Gateway service.

    Here's a general approach you can take:

    1. Azure Functions Proxy:
      • You can use Azure Functions Proxies (previously known as Azure Functions Proxy) to achieve path-based routing.
        • Create an Azure Function App.
          • Add proxy rules to the proxies.json file in your Azure Function App, which will route requests to your client and API based on the URL path.
            • In your proxies.json file, you can define rules like:
                            {
                              "$schema": "http://json.schemastore.org/proxies",
                              "proxies": {
                                "/api": {
                                  "matchCondition": {
                                    "route": "/api/{*path}"
                                  },
                                  "backendUri": "https://your-api.azurewebsites.net/{path}"
                                },
                                "/": {
                                  "matchCondition": {
                                    "route": "/"
                                  },
                                  "backendUri": "https://your-client.azurewebsites.net"
                                }
                              }
                            }
                            
                            
                            
                            ```
    
    - This configuration will route requests to **`/api`** to your API container app and requests to the root path **`/`** to your client container app.
    
    1. **API Gateway Service (Optional)**:
    
       - If you need more advanced features like rate limiting, caching, authentication, or API management, you can consider using Azure API Management. However, as you mentioned, it might be overkill for a small use case.
    
    1. **Custom Domain Configuration**:
    
       - Configure your custom domains (e.g., **`app.example.com`**) for both the Azure Function App (for path-based routing) and your client and API container apps.
    
    1. **DNS Configuration**:
    
       - Ensure your DNS records point to the appropriate Azure resources.
    
    [https://docs.microsoft.com/azure](https://learn.microsoft.com/en-us/azure/container-apps/overview)
    
    Please accept , if it helps., Thanks
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.