The exclude in _routes.json still trigger functions

I created a pages project for proofing of concept.
image

I would like functions to only be trigged when accessed through the top-level path, which is handled by function /functions/[catchall].js
For examples:

https://XXXX.pages.dev/anywords
https://XXXX.pages.dev/any-words

The result is work as expected. I can my code of [catchall].js trigged.

[catchall].js code is below

export function onRequest(context) {
    let result = "this is first level path: \n";
    result += "url: " + context.request.url + "\n";
    for (const header of context.request.headers) {
        result += "header: " + header + "\n";
    }
    return new Response(result);
}

Beyond the top-level path will be immediately redirected to ‘404.html’ without invoking any functions, potentially incurring increased costs due to unwanted traffic.

For examples:

https://XXXX.pages.dev/anywords/unexcepted
https://XXXX.pages.dev/any-words/unexcepted/
https://XXXX.pages.dev/any-words/unexcepted/asdasdasdas

The result is also showing 404 as expected.
image

But I can see the total requests is increased in the Function metrics.

My question is how to use _routes.json to handle only top-level path.
Could someone assist me in achieving this? Thank you very much.

found out the problem. the problem is /favicon.ico after check functions stream log, so add /favicon.ico in exclude property

{
    "version": 1,
    "include": [
        "/*"
    ],
    "exclude": [
        "/*/**",
        "/favicon.ico"
    ]
}

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.