node.jstypescriptnestjs

Can NestJS implement an endpoint with an $ (dollar sign) prefix?


Trying to implement an endpoint in NestJS 10 that conforms to https://www.hl7.org/fhir/R4/operationslist.html and provides an operation via a $ sort of pattern.

Tried using:


@Controller({
  path: '$export',
  version: '1',
})

or

@GET('$export')

Both Return a 404 NotFoundException

I've taken it down in my controller to a bare bones controller and GET but still says not there. I look at swagger docs and its in those correctly but when i run the query from there even it says not found. Any ideas as to how one might implement this pattern?


Solution

  • in your case, use this instead of raw dollar sign

    @GET('/([$])export')
    

    and in case you want to show the regex in swagger

    wrap the regex with backslash \

    something like this

    @GET('/\\([$]\\)export')
    

    https://github.com/pillarjs/path-to-regexp?tab=readme-ov-file#unexpected-----etc