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:
parent
c6839b30c1
commit
5df11c58c7
@ -16,5 +16,6 @@ export async function get(ctx: Context, next) {
|
||||
});
|
||||
|
||||
ctx.body = instance;
|
||||
|
||||
await next();
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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) {
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ async function findUserByToken(ctx: Context, plugin: UsersPlugin) {
|
||||
if (!token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const { userId } = await plugin.jwtService.decode(token);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user