fix: 204 no content response (#378)

* fix: 204 no content response

* Update data-wrapping.ts

* Update plugin.ts

Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
ChengLei Shao 2022-05-22 14:48:50 +08:00 committed by GitHub
parent c6839b30c1
commit 5df11c58c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 2 deletions

View File

@ -16,5 +16,6 @@ export async function get(ctx: Context, next) {
});
ctx.body = instance;
await next();
}

View File

@ -3,19 +3,27 @@ import { Context, Next } from '@nocobase/actions';
export function dataWrapping() {
return async function dataWrapping(ctx: Context, next: Next) {
await next();
if (ctx.withoutDataWrapping) {
return;
}
if (!ctx?.action?.params) {
return;
}
if (ctx.body instanceof Buffer) {
return;
}
if (!ctx.body) {
ctx.body = {};
if (ctx.action.actionName == 'get') {
ctx.status = 404;
}
}
const { rows, ...meta } = ctx.body;
const { rows, ...meta } = ctx.body || {};
if (rows) {
ctx.body = {
data: rows,

View File

@ -73,6 +73,9 @@ export class ClientPlugin extends Plugin {
if (!root) {
return next();
}
if (ctx.path.startsWith(this.app.resourcer.options.prefix)) {
return next();
}
await serve(root)(ctx, next);
// console.log('koa-send', root, ctx.status);
if (ctx.status == 404) {

View File

@ -2,6 +2,7 @@
export function check(options) {
return async function check(ctx, next) {
const { currentUser } = ctx.state;
if (!currentUser) {
return ctx.throw(401, 'Unauthorized');
}

View File

@ -42,6 +42,7 @@ async function findUserByToken(ctx: Context, plugin: UsersPlugin) {
if (!token) {
return null;
}
try {
const { userId } = await plugin.jwtService.decode(token);