happen:
use Koa2 **async** controller with **async** authorizationChecker, still return a 404 in **@Authorized( )** decorator.
version:
typescript: 2.4.2
node: 7.6.0
koa: 2.3.0
routing-controllers: 0.7.2
reflect0metadata: 0.1.10
code:
function sleep( time ) {
return new Promise(( ok ,noOK ) => {
setTimeout(( ) => {
console.log('ok')
ok( );
}, time );
})
}
@JsonController('/users')
export class UserCtrl {
@Get('/')
@Authorized( )
async getAll( ) {
await sleep( 1000 );
return "hahah" // serve return a 404 instead of ‘hahah’
}
}
const app = new Koa( );
useKoaServer( app, {
defaults: {
paramOptions: {
required: true
}
},
authorizationChecker,
routePrefix: '/api',
controllers: [ UserCtrl ]
});
app.listen( 4000 );
async function authorizationChecker( action: Action, roles: string[]) {
console.log('i am authorizationChecker')
await sleep( 1000 );
return true;
}
Again - cannot reproduce:
import { JsonController, Get, Authorized, useKoaServer, Action } from "routing-controllers";
import * as Koa from "koa";
const sleep = (time: number) => new Promise(resolve => setTimeout(resolve, time));
@JsonController("/users")
export class UserCtrl {
@Get("/")
@Authorized()
async getAll() {
console.log(Date.now(), "inside authorized getAll")
await sleep(1000);
return "hahah"; // serve return a 404 instead of ‘hahah’
}
}
async function authorizationChecker(action: Action, roles: string[]) {
console.log(Date.now(), "inside authorizationChecker")
await sleep(1000);
return true;
}
const app = new Koa();
useKoaServer(app, {
defaults: {
paramOptions: {
required: true,
},
},
authorizationChecker,
routePrefix: "/api",
controllers: [UserCtrl],
});
app.listen(4000, () => console.log("listening 4000"));
package-lock.json:
"routing-controllers": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/routing-controllers/-/routing-controllers-0.7.2.tgz",
"integrity": "sha1-rOEUUBNJPPFCFPsTDsTwiGa8zts=",
// ...
"koa": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/koa/-/koa-2.3.0.tgz",
"integrity": "sha1-nh6OTaQBg5xXuFJ+rcV/dhJ1Vac=",


i got the same issue, controller method execute properly without authorizationChecker, when using authorizationChecker,i got the 404 .
Ok, looks like the problem is with new versions of koa/koa-router/sth? I created a new project folder with fresh install of modules and I can reproduce the issue.
Here is the reproduce code to clone and npm install:
https://gist.github.com/19majkel94/cbdc281c35bd24f01f219346f5189a8c
Will check our test suite if the issue is still here.
Hey all, I can confirm this bug. I tried it with a freshly created project using the code and steps @19majkel94 posted. Here is my package.json. I'm running on Node v8.5.0 on a Lubuntu 16.04.3 machine with ES2017 as my typescript target.
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^8.0.29",
"ts-node": "^3.3.0",
"typescript": "^2.5.2"
},
"dependencies": {
"@types/koa": "^2.0.39",
"@types/koa-bodyparser": "^3.0.25",
"@types/koa-router": "^7.0.23",
"koa": "^2.3.0",
"koa-bodyparser": "^4.2.0",
"koa-router": "^7.2.1",
"npx": "^9.6.0",
"routing-controllers": "^0.7.2"
}
}
Sorry guys, looks like it's fixed and just waiting for release 0.7.3.
the issue is not totally settled, i uninstall routing-controller, and install the new "fixed" routing-controllers,when i use authorizationChecker and in controller use promise and setTimeout, it return 404 again!
i uninstall routing-controller, and install the new "fixed" routing-controllers
It's not published yet, do you installed from the master branch?
I'll publish it today. Guys please don't forget (and users to update) CHANGELOG as well. New version is here, but changelog is empty
i install 0.7.3 version, it works correctly, no 404 emerges ever , thx!
Change log is empty because AFAIK they were only bugfixes. Changelog is for more meaningful changes like breaking changes, right? Only custom driver is a new change but useful for 3 peoples in the world 😝
@pleerock
We have a project board to keep track of merged and released PR:
https://github.com/pleerock/routing-controllers/projects/3
Changelog is for more meaningful change
No, actually if should be for bugfixes as well and every change we made, thats why it's called a changelog 😄
Yeah but we can't left versions empty in there. If its only bugs then we need at least write here "fixed bugs #x #y #z"
@NoNameProvided @pleerock
Done in https://github.com/pleerock/routing-controllers/commit/7e5fb34c2cfedbc2f33b6cc3f76818938490505e thanks to the project board 😄
@19majkel94 @pleerock Thx guys! Nice to meet Routing-controllers! : )
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Sorry guys, looks like it's fixed and just waiting for release
0.7.3.