loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

Case insensitive routing

Open dkrantsberg opened this issue 6 years ago • 2 comments

While porting a legacy API to LoopBack 4 I've noticed that LoopBack routing is case sensitive. Is there a way to make it case insensitive so that it doesn't throw 404 errors if route casing is different (/api/userprofile or /api/userProfile)?

Case-insensitive routing is default in Express.js. I was expecting LB4 to behave the same way.

dkrantsberg avatar Feb 13 '20 21:02 dkrantsberg

@dkrantsberg AFAIK, lb4 only uses Express.js for its middlewares, and uses its own routing engine. (see Circling back to Express with a twist).

lb4 does have the concept of Sequences (where the REST router is invoked), to which you can "normalize" the incoming route path before passing it into the router's findRoute()by extending and modifying DefaultSequence (see Invoke Operations using Routes) .

You can also completely replace the REST router for more flexibility (see Customize the REST router).

achrinza avatar Feb 14 '20 08:02 achrinza

Yes, this is what I ended up doing. Thanks, @achrinza.

dkrantsberg avatar Feb 14 '20 16:02 dkrantsberg