Skip to content

Commit

Permalink
chore: refact
Browse files Browse the repository at this point in the history
  • Loading branch information
npmstudy committed Nov 1, 2023
1 parent 739c4f0 commit 84a9529
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/core2/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import RpcServer from './src/server';

const rpc = new RpcServer({});

const fn = new Fn();
const demo = new Demo();
const fn = new Fn({});
const demo = new Demo({});

rpc.plugin(fn);
rpc.plugin(demo);
Expand Down
4 changes: 2 additions & 2 deletions packages/core2/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Plugable from './src/base';
export default class Fn extends Plugable {
// public name: string;

constructor() {
super();
constructor(cfg?) {
super(cfg);

this.prefix = '/demo';
// this.name = 'fn';
Expand Down
5 changes: 4 additions & 1 deletion packages/core2/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface Strategy {
app;
compose;
proxy;
config;
server;
serverConfig;
}
Expand All @@ -29,8 +30,10 @@ export default class Plugable implements Strategy {
public serverConfig;
public prefix;
public compose;
public config;

constructor() {
constructor(cfg?) {
this.config = Object.assign({}, cfg);
this.name = 'base';
this.app = new Koa();
this.init = [];
Expand Down
8 changes: 6 additions & 2 deletions packages/core2/src/fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Plugable from './base';
export default class Fn extends Plugable {
// public name: string;

constructor() {
super();
constructor(cfg?: any) {
super(cfg);

this.prefix = '/api';
// this.name = 'fn';
Expand All @@ -16,6 +16,10 @@ export default class Fn extends Plugable {

const c = this.c();
// this.addLoad(c);
this.server['fn'].add = function (i) {
if (!this.config['functions']) this.config['functions'] = [];
this.config['functions'].push(i);
};
}
process() {
return async (ctx, next) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/core2/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ export default class RpcServer {
plugin.serverConfig = this.config;

// set config namespace
if (plugin.name !== 'base') this.config.plugin[plugin.name] = {};
if (plugin.name !== 'base') {
console.error('plugin name 没有修改,可能会出现serverConfig获取问题,请关注');
}
this.config.plugin[plugin.name] = plugin.config;

if (plugin.init.length > 0) this.config.hooks.init.push(...plugin.init);

Expand Down

0 comments on commit 84a9529

Please sign in to comment.