Skip to content

No way to reject a route #1893

@CobusKruger

Description

@CobusKruger

Describe the bug

Let's say I want to have an SPA served from https://example.com, and its APIs from https://example.com/api/name-of-api.

I would imagine setting up the two routes like this:

[
    {
        "RouteId": "app",
        "Match": {
            "Path": "/{**any}"
        },
        "ClusterId": "app"
    },
    {
        "RouteId": "first-api",
        "Match": {
            "Path": "/api/first-api/{*any}"
        },
        "ClusterId": "first-api"
    },
    {
        "RouteId": "second-api",
        "Match": {
            "Path": "/api/second-api/{*any}"
        },
        "ClusterId": "second-api"
    }
]

All three of these URLs will work as intended:
https://example.com/
https://example.com/api/first-api
https://example.com/api/second-api

But this URL will also be accepted, and quietly return the same as https://example.com
https://example.com/api/third-and-totally-invalid-api

Ideally, I would want to instruct the proxy to reject that route with a 404, perhaps with something like this:

    {
        "RouteId": "invalid-api",
        "Match": {
            "Path": "/api/{*any}"
        },
        StatusCode: 404
    },

To Reproduce

Listed in the description

Further technical details

Yarp.ReverseProxy 1.1.1
On Windows 10, .NET 6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: EnhancementNew feature or requestsingle_exeIssues that apply when a shipping YARP as a single exe

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions