`New-PSUEndpoint -Regex` results in 404

I’m trying to create the following API endpoint:

New-PSUEndpoint -Url '^foo\/bar(?<varA>\/subpath|)' -Regex -Endpoint {
    Param(
        [string]$varA
    )

    [...]
}

The new endpoint does show up in the Admin interface, but when trying to access it, I get a 404 response for both localhost:5000/foo/bar and localhost:5000/foo/bar/subpath

In Windows eventlogs, I do not see any useful error I can troubleshoot with. What am I doing wrong?

Product: PowerShell Universal
Version: 2.5.3

You need a slight adjustment to your regex since the ‘/’ is included in the path it’s trying to match.

New-PSUEndpoint -Url '^\/regex\/works' -Regex -Endpoint {
    "regex"
}

New-PSUEndpoint -Url '^\/foo\/bar(?<varA>\/subpath|)' -Regex -Endpoint {
    Param(
        [string]$varA
    )

    $VarA
}

Here’s how I’m calling and validating them. Notice that the subpath contains the forward slash.

        It "should work with regex with params" {
            Invoke-RestMethod http://localhost:5000/foo/bar/subpath | Should -Be "/subpath"
        }

        It "should work with regex" {
            Invoke-RestMethod http://localhost:5000/regex/works | Should -Be "regex"
        }

I actually also tried that syntax with the escaped slash in front, but I’m still getting 404 response, and no error anywhere.

I tried with or without -ErrorAction Stop, but nothing changes.

Can you do me a favor and crank up your log level to debug and send it my way? It seems like it should be finding these paths.

Debugging logs:

2021-11-22 07:59:32.751 +00:00 [DBG] Adding endpoint: (GET) ^\/foo\/bar(?<format>\/subpath|)
2021-11-22 08:00:03.213 +00:00 [INF] Starting groom job.
2021-11-22 08:00:03.221 +00:00 [INF] Groom date is: 10/23/2021 8:00:03 AM
2021-11-22 08:00:03.225 +00:00 [INF] Old jobs: 0
2021-11-22 08:00:03.230 +00:00 [INF] Finished groom job.
2021-11-22 08:00:47.973 +00:00 [INF] Request starting HTTP/1.1 GET http://localhost:5000/foo/bar - -
2021-11-22 08:00:47.974 +00:00 [DBG] AuthenticationScheme: Negotiate was not authenticated.
2021-11-22 08:00:47.974 +00:00 [DBG] No response compression available, the Accept-Encoding header is missing or invalid.
2021-11-22 08:00:47.974 +00:00 [DBG] The request path /foo/bar does not match a supported file type
2021-11-22 08:00:47.974 +00:00 [DBG] The request path  does not match the path filter
2021-11-22 08:00:47.974 +00:00 [DBG] No candidates found for the request path '/foo/bar'
2021-11-22 08:00:47.974 +00:00 [DBG] Request did not match any endpoints
2021-11-22 08:00:47.976 +00:00 [DBG] The request path /foo/bar does not match a supported file type
2021-11-22 08:00:47.977 +00:00 [DBG] The request path  does not match the path filter
2021-11-22 08:00:47.977 +00:00 [DBG] No candidates found for the request path '/foo/bar'
2021-11-22 08:00:47.977 +00:00 [DBG] Request did not match any endpoints
2021-11-22 08:00:47.978 +00:00 [DBG] Connection id "0HMDDHNSKRTJJ" completed keep alive response.
2021-11-22 08:00:47.978 +00:00 [INF] Request finished HTTP/1.1 GET http://localhost:5000/foo/bar - - - 404 0 - 5.0869ms
2021-11-22 08:00:49.452 +00:00 [INF] Request starting HTTP/1.1 GET http://localhost:5000/foo/bar/subpath - -
2021-11-22 08:00:49.452 +00:00 [DBG] AuthenticationScheme: Negotiate was not authenticated.
2021-11-22 08:00:49.452 +00:00 [DBG] No response compression available, the Accept-Encoding header is missing or invalid.
2021-11-22 08:00:49.452 +00:00 [DBG] The request path /foo/bar/subpath does not match a supported file type
2021-11-22 08:00:49.452 +00:00 [DBG] The request path  does not match the path filter
2021-11-22 08:00:49.452 +00:00 [DBG] No candidates found for the request path '/foo/bar/subpath'
2021-11-22 08:00:49.452 +00:00 [DBG] Request did not match any endpoints
2021-11-22 08:00:49.454 +00:00 [DBG] The request path /foo/bar/subpath does not match a supported file type
2021-11-22 08:00:49.454 +00:00 [DBG] The request path  does not match the path filter
2021-11-22 08:00:49.454 +00:00 [DBG] No candidates found for the request path '/foo/bar/subpath'
2021-11-22 08:00:49.454 +00:00 [DBG] Request did not match any endpoints
2021-11-22 08:00:49.456 +00:00 [DBG] Connection id "0HMDDHNSKRTJJ" completed keep alive response.
2021-11-22 08:00:49.456 +00:00 [INF] Request finished HTTP/1.1 GET http://localhost:5000/foo/bar/subpath - - - 404 0 - 4.2061ms

Shameless bump; do the logs help you in any way to see what’s happening?

I don’t notice anything except potentially the authentication method (Windows auth?) that may be different in my environment. Do you have a lot of other endpoints in this environment?

No, it doesn’t even work if I leave it as the only endpoint…

Ok. Let me try setting up Windows auth and see if that changes things for me.

Even when I delete authentication.ps1 and go back to default settings, I still cannot get the regex endpoint to work; the line regarding authentication changes to AuthenticationScheme: Cookies was not authenticated. Rest stays the same.

For what it’s worth, I’m installing PSU through chocolatey (tried 2.5.5 as well) on Windows Server 2019 Standard 1809

Can we open a case for this? I’d like to schedule a call and take a look since I can’t reproduce it.

You can email support@ironmansoftware.com to do so.

Sorry for not replying; I was on vacation for the holidays, and to allow my colleagues to continue working with the configuration, I just duplicated the endpoints to avoid having to use regex at all.

Maybe in the future we’ll work on technical debt and want to retry regex endpoints.

1 Like