http://localhost:3000/endpoint?id=83 results in 404 (Not Found). All other routes work as expected. Am I missing something here?
router
.get('/', function *(next) {
yield this.render('index.ejs', {
title: 'title set on the server'
});
})
.get('/endpoint:id', function *(next) {
console.log('/endpoint:id');
console.log(this.params);
this.body = 'Endpoint return';
})
koa-router documentation on parameters
//Named route parameters are captured and added to ctx.params.
router.get('/:category/:title', function *(next) {
console.log(this.params);
// => { category: 'programming', title: 'how-to-node' }
});
Request in angular controller:
$http.get('/endpoint', {params: { id: 223 }})
.then(
function(response){
var respnse = response.data;
console.log(response);
}
);
Your parameter format is not right
Replace your route with this
.get('/endpoint/:id', function *(next) {
console.log(this.params);
this.body = 'Endpoint return';
})
.get('/endpoint/', function *(next) {
console.log(this.query);
this.body = 'Endpoint return';
})
.get('/endpoint/:id', function *(next) {
console.log(this.params);
this.body = 'Endpoint return';
})