Closed allinwind3344 closed 8 years ago
check the code , alias will override prefix, postfix, suffix and so on. my understand is alias '/alist' should just override the 'list' part, right?
@allinwind3344 Right now the only support for alias is full override (which is necessary). But this is an interesting use case. Is there a reason you wouldn't just change the pattern to cmd:alist
. I'm trying to understand why you would sub alias a pattern.
@mcdonnelldean thanks for your reply. i want to use prefix to distinguish different functionality in my project. for example, to define restful api as below route:
{
prefix: '/user',
pin: 'role:user,cmd:*',
map: {
load: {GET:true, alias: '/:id'},
edit: {PUT: true, alias: '/'},
create: {POST: true, alias: '/'},
delete: {DELETE: true, alias: '/:id'},
}
}
}
in the most of CRUD cases, the 'map' part is same or similar, use 'prefix' as identifying is clearly and even 'map' part can be reused for different functionality.
@allinwind3344 Ah ok, in that case you are looking for suffix which is not yet added, see #87.
@tswaters Nice simple one here for you if you are interested.
@mcdonnelldean I'm not sure if using suffix can do what is desired.
With a REST end point, the desired routes would be:
GET /user/:id PUT /user POST /user DELETE /user/:id
Whereas using suffix in this manner would create:
GET /user/load/:id PUT /user/edit/ POST /user/create/ DELETE /user/delete/:id
The problem here is that when alias has been defined, it completely blows away everything else that has been defined.... so the routes end up being:
GET /:id PUT / POST / DELETE /:id
Maybe could be as simple as providing the option to overwrite the name? Right now the key of the map is always exposed as the route.
e.g.,
{
prefix: '/api',
pin: 'cmd:*',
map: {
myHairyLookinInternalCommandName: true
}
}
results in /api/myHairyLookinInternalCommandName
If one could overwrite the name of the path, the REST example could be accomplished passing name as a blank string, just to get rid of the 'load/edit/create/delete' names:
{
prefix: '/user',
pin: 'role:user,cmd:*',
map: {
load: {GET:true, name: '', suffix: '/:id'},
edit: {PUT: true, name: ''},
create: {POST: true, name: ''},
delete: {DELETE: true, name: '', suffix: '/:id'},
}
}
Results in the desired:
GET /user/:id PUT /user POST /user DELETE /user/:id
I'll put a PR together for what I've described above.... I did do the suffix piece, and I was about to write how it works here when I realized that no, that wouldn't accomplish the goal due to the names still being there.
@allinwind3344 @tswaters Suffix is now on master so I'm going to close this; It'll get released tonight. @allinwind3344 as mentioned by @tswaters, you may still need the work from #97 to get exactly what you need.
route mapping with alias not work under windows.
amend the using express sample route as below:
access "http://localhost:4000/todo/alist" by chrome and return 404 error.
dependent packages: "seneca": "^3.0.0", "seneca-web": latest source code download from master "express": "^4.14.0",
OS: windows 7