Open idaho opened 2 years ago
I dug a little deeper and found the root cause: Feathers does not mount the service middleware in the express app at a route with URL parameters (e.g. users/:userId
) but always at /
. That prevents express from recognizing and decoding URL params.
@daffl, what do you think about decoding the URL params in feathers express within the function servicesMiddleware
after the service lookup? I'd be happy to create a pull request if this is the right direction.
Package.json extract:
"@feathersjs/express": "^5.0.25",
"@feathersjs/feathers": "^5.0.25",
I created a feathers express app like so:
const feathersApp: AxApplication = feathersExpress(feathers());
When executing feathersApp.service('users', new UserService())
, the service is registered at feathersApp.services
. It makes sense that no middleware is registered in express at this point since this code is part of the more generic feathers application itself that needs to work with various transports.
Feathers express registers a middleware function at /
during the feathers express initialization. It basically replaces the native express lookup with a feathers-internal lookup.
Since the path /
does not include any URL params, express can't recognize those params and won't decode them.
Steps to reproduce
Since the update to pre-release 5.0.0-pre.16, we no longer have a decoded ID in the service get method. We use the Feathers Express application and have an ID containing a
/
which is encoded. Before we upgraded to this version, it seems there was a built-in decoding for the ID.Example
If we now run the application and make a request to http://localhost:3040/foo, we see a result list containing the created entry with the ID
en/tmp
. However, when we send a request to http://localhost:3040/foo/en%2Ftmp, we get the error No record found for IDen%2Ftmp
. Before the update, the ID was URI decoded and the record was found.Currently, we have a workaround where we do the decoding manually in the service method, as shown below.
System configuration
feathersjs: since packages 5.0.0-pre.16
NodeJS version: 16.3.2
Operating System: MacOS 12.2.1
Module Loader: typescript / commonjs
Typescript: 4.5.5