moleculerjs / moleculer-web

:earth_africa: Official API Gateway service for Moleculer framework
http://moleculer.services/docs/moleculer-web.html
MIT License
293 stars 119 forks source link

Bug | Named route will not match #208

Closed omerts closed 3 years ago

omerts commented 4 years ago

Hey,

I run into this trying to add CORS support, and the browser is sending an OPTIONS request. I have a path called "/storage"

Seems like routes will never match due to the following: Index.js line number 140:

  if (url.length > 1 && url.endsWith("/"))
   url = url.slice(0, -1);

Which removes any trailing slashes from the url

On the other hand line 1267:

route.path = addSlashes(globalPath) + (opts.path || "");

Meaning it always adds a trailing slash to the end of the route

So line 169, will never be true:

if (url.startsWith(route.path)) {

As url will never have a trailing slash, while route.path will always have one.

intech commented 4 years ago

Thanks for the report! Please make a test repository with this bug to reproduce it.