Skip to content

Commit

Permalink
fix: rest routes won't continue after body is set
Browse files Browse the repository at this point in the history
  • Loading branch information
gerard2perez committed Sep 17, 2017
1 parent 93386a7 commit d942490
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 8 deletions.
2 changes: 1 addition & 1 deletion src/middleware/oauth2server.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function oauth2server () {
'refresh_token': [3, 2]
};
router.post('/token/',
passport.authenticate(['local', 'bearer', 'basic', 'oauth2-client-password'], { session: false }),
passport.authenticate(['local', 'bearer', /* 'basic', */ 'oauth2-client-password'], { session: false }),
async function token (ctx, next) {
await next();
ctx.state = {
Expand Down
1 change: 0 additions & 1 deletion src/support/KoatonRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ async function findmodel (ctx, next) {
* @return {Object} {status:401, body: null}
*/
async function protect (ctx, next) {
console.log('Im Protect', ctx.isAuthenticated());
if (ctx.isAuthenticated()) {
await next();
} else {
Expand Down
6 changes: 0 additions & 6 deletions src/support/RestModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,11 @@ export function RestModel (options, route, modelname) {
}
res[modelname] = rawmodels;
ctx.body = res;
await next();
});
pOrp(routers, options.get).get('/:id', async function REST_GET_ID (ctx, next) {
let res = {};
res[inflector.singularize(modelname)] = await restify(await ctx.model.findById(ctx.params.id), ctx.model.relations, ctx.model);
ctx.body = res;
await next();
});
pOrp(routers, options.post).post('/', async function REST_POST (ctx, next) {
let res = {};
Expand All @@ -235,7 +233,6 @@ export function RestModel (options, route, modelname) {
}
ctx.status = 201;
ctx.body = res;
await next();
});
pOrp(routers, options.post).post('/:id/:child', async function REST_POST_ID (ctx, next) {
let parent = await ctx.model.findById(ctx.params.id);
Expand All @@ -262,7 +259,6 @@ export function RestModel (options, route, modelname) {
let res = {};
res[inflector.singularize(modelname)] = await restify(parent, ctx.model.relations, ctx.model);
ctx.body = res;
await next();
});
pOrp(routers, options.put).put('/:id', async function REST_PUT (ctx, next) {
let body = ctx.request.body[inflector.singularize(modelname)];
Expand All @@ -276,14 +272,12 @@ export function RestModel (options, route, modelname) {
record = await REST_POST_SINGLE(ctx.model, body, record);
ctx.body = {};
ctx.body[inflector.singularize(modelname)] = record;
await next();
});
pOrp(routers, options.delete).del('/:id', async function REST_DELETE (ctx, next) {
await ctx.model.destroyById(ctx.params.id);
ctx.body = {
id: ctx.params.id
};
await next();
});
routers.path = path.join('/', mountRoute);
return routers;
Expand Down

0 comments on commit d942490

Please sign in to comment.