diff --git a/packages/core/resourcer/src/resource.ts b/packages/core/resourcer/src/resource.ts index b53026e95..432411dbe 100644 --- a/packages/core/resourcer/src/resource.ts +++ b/packages/core/resourcer/src/resource.ts @@ -61,7 +61,7 @@ export class Resource { public readonly except: Array; 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) { diff --git a/packages/core/resourcer/src/resourcer.ts b/packages/core/resourcer/src/resourcer.ts index b959d234b..ac406dd80 100644 --- a/packages/core/resourcer/src/resourcer.ts +++ b/packages/core/resourcer/src/resourcer.ts @@ -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) => { + restApiMiddleware({ prefix, accessors }: KoaMiddlewareOptions = {}) { + return async (ctx: ResourcerContext, next: () => Promise) => { ctx.resourcer = this; let params = parseRequest( { @@ -332,7 +331,6 @@ export class Resourcer { return next(); } }; - return restApiMiddleware; } middleware(options: KoaMiddlewareOptions = {}) { diff --git a/packages/core/server/src/application.ts b/packages/core/server/src/application.ts index 769060b3c..00a955b11 100644 --- a/packages/core/server/src/application.ts +++ b/packages/core/server/src/application.ts @@ -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 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);