Coder Social home page Coder Social logo

Comments (16)

JozefFlakus avatar JozefFlakus commented on May 16, 2024 3

@zeucxb fixed with v1.1.1 patch 💪

from marble.

zeucxb avatar zeucxb commented on May 16, 2024 2

Sorry, I have tried in the version that was running in the project here.

But checking the urlParams.factory.ts it should have worked. So I created a new project with the current stable version and it works.

👎 Sorry 👎

from marble.

krzysztof-miemiec avatar krzysztof-miemiec commented on May 16, 2024 2

@zeucxb I think you can try with a named param there, i.e.: matchPath: /:type(api|rest)/:file, then you should get {type: "api", file: "test.json"} as a result for /api/test.json.

The naming is probably a bug on our side, as path-to-regexp docs state that:

It is possible to write an unnamed parameter that only consists of a matching group. It works the same as a named parameter, except it will be numerically indexed.

from marble.

zeucxb avatar zeucxb commented on May 16, 2024 2

Yeah @krzysztof-miemiec it works. Awesome!!!

from marble.

krzysztof-miemiec avatar krzysztof-miemiec commented on May 16, 2024 1

Internally Marble uses https://github.com/pillarjs/path-to-regexp which supports passing regexp to parameters. However everything has to be written as string. Have you tried .matchPath('/(api|rest)/(.*)')?

from marble.

krzysztof-miemiec avatar krzysztof-miemiec commented on May 16, 2024 1

If you're thinking about something more fancy, like writing actual regular expressions, it's not supported yet, but it's definitely doable. We'd have to think about regex pattern merging for nested routing. It's simple to get regex patterns and concatenate them, but I bet that sooner or later we'll get something like: /my/parent/path/ and /^\/(to-be|not-to-be)\/.+$/ and for any given route it will be simply evaluated as false, because of ^ in the middle. Then we'd have to remove one of the duplicated \/ inside and so on... So, for now I came up with:

  • get both parent and child path parts and simply concatenate them as string
  • remove all ^ and $ from that stringified regex (also using regex, what a perversion 😜 )
  • .replace(([\\/]{2,})/g, '/')
  • somehow extract all capturing groups and assign them to parameters; What should we do with groups that were defined in regex? There is a specification for named capturing groups that we could use, but AFAIK they haven't landed in JS. We can simply mark all groups from regex as non-capturing, but this has to be done earlier, before concatenation.
  • append ^ and $ once again
  • probably check for possibility of hacks on such routing mechanism

Since Marble is one of the milion solutions available, the above is probably redundant and someone might have implemented such merger.

from marble.

JozefFlakus avatar JozefFlakus commented on May 16, 2024 1

So far this kind of advanced routing is not documented and wasn't tested before. We should cover these features with test cases first. Thanks @zeucxb for pointing this out.

from marble.

JozefFlakus avatar JozefFlakus commented on May 16, 2024 1

It is a bug. @zeucxb please create a separate issue so we can track it properly :)

from marble.

JozefFlakus avatar JozefFlakus commented on May 16, 2024

@zeucxb have you tested it with stringified Regex? 👇
#67 (comment)

from marble.

zeucxb avatar zeucxb commented on May 16, 2024

But we have a problem if try to use regex and special params.

ex.

matchPath: /(api|rest)/:file

request: /rest/test.json

params: { file: "rest" }

from marble.

zeucxb avatar zeucxb commented on May 16, 2024

And without the special param (only with regex) we cannot get url params.

from marble.

JozefFlakus avatar JozefFlakus commented on May 16, 2024

re: #67 (comment)
Can you post also the example regex / path that was used within matchPath?

from marble.

zeucxb avatar zeucxb commented on May 16, 2024

@JozefFlakus this?

With :file

matchPath: /(api|rest)/:file

request: /rest/test.json

params: { file: "rest" }

Without :file

matchPath: /(api|rest)/(.*)

request: /rest/test.json

params: { }

from marble.

JozefFlakus avatar JozefFlakus commented on May 16, 2024

Thanks. Custom regex is problematic because params are mapped over declared names in order they occured, eg. /(api|rest)/:file has a one named parameter, which in result will be mapped to the first capturing grup. Maybe we should mach it in more precise way @krzysztof-miemiec? 🤔

from marble.

zeucxb avatar zeucxb commented on May 16, 2024

I was about to say that we should have routes' documentation. 😄

from marble.

zeucxb avatar zeucxb commented on May 16, 2024

I was going to open another issue but I don't know if it's an expected behavior.

I've this code in my application:

const web$ = combineRoutes("/admin", [
  EffectFactory
    .matchPath('/:dir')
    .matchType('GET')
    .use((req$) => ...), 
  EffectFactory
    .matchPath('*')
    .matchType('GET')
    .use((req$) => ... ),
]);

In this case a request to /admin gets 404 but /admin/ works fine.

If I change the code to:

const web$ = combineRoutes("/admin", [
  EffectFactory
    .matchPath('/:dir')
    .matchType('GET')
    .use((req$) => ...), 
  EffectFactory
    .matchPath('/')
    .matchType('GET')
    .use((req$) => ... ),
]);

Both /admin and /admin/ works.

from marble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.