refactor(core): simplify some code (#895)
This commit is contained in:
parent
dce6558b55
commit
6c929039b1
@ -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) {
|
||||
|
@ -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 = {}) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user