refactor(core): simplify some code (#895)

This commit is contained in:
Junyi 2022-10-12 15:22:00 +08:00 committed by GitHub
parent dce6558b55
commit 6c929039b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 18 deletions

View File

@ -61,7 +61,7 @@ export class Resource {
public readonly except: Array<ActionName>;
constructor(options: ResourceOptions, resourcer: Resourcer) {
const { middleware, middlewares, actions = {} } = options;
const { middleware, middlewares, actions = {}, only = [], except = [] } = options;
this.options = options;
this.resourcer = resourcer;
this.middlewares = Middleware.toInstanceArray(middleware || middlewares);
@ -71,7 +71,6 @@ export class Resource {
actions[name as string] = handler;
}
}
const { only = [], except = [] } = options;
if (except.length > 0) {
excludes = except;
} else if (only.length > 0) {

View File

@ -267,9 +267,8 @@ export class Resourcer {
this.middlewares.add(middlewares, options);
}
restApiMiddleware(options: KoaMiddlewareOptions = {}) {
const { prefix, accessors } = options;
const restApiMiddleware = async (ctx: ResourcerContext, next: () => Promise<any>) => {
restApiMiddleware({ prefix, accessors }: KoaMiddlewareOptions = {}) {
return async (ctx: ResourcerContext, next: () => Promise<any>) => {
ctx.resourcer = this;
let params = parseRequest(
{
@ -332,7 +331,6 @@ export class Resourcer {
return next();
}
};
return restApiMiddleware;
}
middleware(options: KoaMiddlewareOptions = {}) {

View File

@ -1,3 +1,4 @@
import { promisify } from 'util';
import { ACL } from '@nocobase/acl';
import { registerActions } from '@nocobase/actions';
import Database, { Collection, CollectionOptions, IDatabaseOptions } from '@nocobase/database';
@ -378,18 +379,8 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
// close http server
if (this.listenServer) {
const closeServer = () =>
new Promise((resolve, reject) => {
this.listenServer.close((err) => {
if (err) {
return reject(err);
}
this.listenServer = null;
resolve(true);
});
});
await closeServer();
await promisify(this.listenServer.close)();
this.listenServer = null;
}
await this.emitAsync('afterStop', this, options);