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;
|
ctx.body = instance;
|
||||||
|
|
||||||
await next();
|
await next();
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,27 @@ import { Context, Next } from '@nocobase/actions';
|
|||||||
export function dataWrapping() {
|
export function dataWrapping() {
|
||||||
return async function dataWrapping(ctx: Context, next: Next) {
|
return async function dataWrapping(ctx: Context, next: Next) {
|
||||||
await next();
|
await next();
|
||||||
|
|
||||||
if (ctx.withoutDataWrapping) {
|
if (ctx.withoutDataWrapping) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx?.action?.params) {
|
if (!ctx?.action?.params) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.body instanceof Buffer) {
|
if (ctx.body instanceof Buffer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.body) {
|
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) {
|
if (rows) {
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
data: rows,
|
data: rows,
|
||||||
|
@ -73,6 +73,9 @@ export class ClientPlugin extends Plugin {
|
|||||||
if (!root) {
|
if (!root) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
if (ctx.path.startsWith(this.app.resourcer.options.prefix)) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
await serve(root)(ctx, next);
|
await serve(root)(ctx, next);
|
||||||
// console.log('koa-send', root, ctx.status);
|
// console.log('koa-send', root, ctx.status);
|
||||||
if (ctx.status == 404) {
|
if (ctx.status == 404) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
export function check(options) {
|
export function check(options) {
|
||||||
return async function check(ctx, next) {
|
return async function check(ctx, next) {
|
||||||
const { currentUser } = ctx.state;
|
const { currentUser } = ctx.state;
|
||||||
|
|
||||||
if (!currentUser) {
|
if (!currentUser) {
|
||||||
return ctx.throw(401, 'Unauthorized');
|
return ctx.throw(401, 'Unauthorized');
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ async function findUserByToken(ctx: Context, plugin: UsersPlugin) {
|
|||||||
if (!token) {
|
if (!token) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { userId } = await plugin.jwtService.decode(token);
|
const { userId } = await plugin.jwtService.decode(token);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user