-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The parameters doesn't work #64
Comments
Colon isn't an accepted URI templates prefix in this router. Use # for numbers and $ for anything else. Your example should look like /user/#id. I'm a little behind on the docs for this, I'll give it a pass tomorrow. |
I just gave a first pass to the SimpleRouter docs: https://github.com/Dashron/roads#simplerouterroad-road. Let me know if you have any questions. Also, I wanted to give you heads up that I'm moving the body parsing into middleware. I'll make sure to document the change. |
|
At the moment I'm keeping that private, I should probably rename it to You should use |
Ok, but I have a question. If I want to create a middleware before or after of execute a route, how would I do it? Image that I want to check something before of execute this route, a validation data for example. |
There are some examples in the
Let me know if you want further examples |
It would be cool an example about this case that I mentioned before please |
sure. I just added a new section to https://github.com/Dashron/roads/blob/master/README.md#use-callback called "How do I control the order my logic executes?". Let me know if that clears it up |
Yes now I understand completly. For example to create a before and after middleware I can do this. app.use(function (method, path, body, headers, next) {
console.log('A ' + method + ' request was made to ' + JSON.stringify(path));
if(next) return next();
});
router.addRoute("GET", "/user/#id", (url: any, body: any, headers: Headers, next: Function) => {
console.log(`These are the parameter user ${JSON.stringify(url.args)}`);
return next();
});
router.addRoute("GET", "/person", (url: any, body: any, headers: Headers, next: Function) => {
console.log("This is a example");
return next();
});
router.applyMiddleware(app);
app.use((method, path: any, body, headers, next) => {
if(path.path === '/user/5') {
console.log("10");
return new Response({id: "10"}, 200);
}
if(next) return next();
}); |
I have only two small comments on your example.
router.addRoute("GET", "/person", (url: any, body: any, headers: Headers, next: Function) => {
console.log("This is a example");
return next()
.then(function (response) {
if(path.path === '/user/5') {
console.log("10");
return new Response({id: "10"}, 200);
}
});
});
|
About the if was some problem with the typescript that I put it as optional argument and typescript force you to put |
I consider that the parameters is resolved because of this I closed this issue |
The parameters doesn't works. This I have in routes
If I request with
curl -X GET http://localhost:3000/user/4
it return undefined but I I change the router without parameter and requestcurl -X GET http://localhost:3000/user
it receive a body correctlyThe text was updated successfully, but these errors were encountered: