Comments (16)
@zeucxb fixed with v1.1.1 patch 💪
from marble.
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.
@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.
Yeah @krzysztof-miemiec it works. Awesome!!!
from marble.
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.
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.
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.
It is a bug. @zeucxb please create a separate issue so we can track it properly :)
from marble.
@zeucxb have you tested it with stringified Regex? 👇
#67 (comment)
from marble.
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.
And without the special param (only with regex) we cannot get url params.
from marble.
re: #67 (comment)
Can you post also the example regex / path that was used within matchPath
?
from marble.
@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.
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.
I was about to say that we should have routes' documentation. 😄
from marble.
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)
- `URIError: URI malformed` exception crashes server for named route parameters HOT 4
- HTTP Header with case-insensitive header names HOT 7
- 'Error: WebSocket is not open' when closing two connected ws clients simultaneously HOT 8
- Type-safe request extensions HOT 7
- RabbitMq client still a Promise on App start up HOT 6
- Error [ERR_PACKAGE_PATH_NOT_EXPORTED] when using rxjs v7 HOT 5
- fp-ts-rxjs bindings with requestValidator$ HOT 1
- Cannot find module 'rxjs/internal/scheduler/AsyncScheduler' from 'node_modules/@marblejs/core/dist/effects/effectsContext.factory.js' when running jest HOT 3
- Websocket timeout causes process to crash HOT 11
- path-to-regexp is not listed in dependencies HOT 6
- Wrong warning message about eventBus & eventBusClient binding order HOT 2
- HttpErrorEffect stop the server and result with "Cannot read property 'response' of undefined" HOT 2
- Have a way to listen to the CQRS event bus arbitrarily HOT 4
- Replace unsupported busboy version with fastify fork
- Latest fp-ts and io-ts do not work with event HOT 3
- Server side events / Server sent events HOT 2
- LoggerTag is undefined
- Add Redis Streams support for messaging
- Documentation - Not Loading HOT 1
- Type-safe for client side who use our API.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marble.