Skip to content

Commit

Permalink
chore: stash
Browse files Browse the repository at this point in the history
  • Loading branch information
npmstudy committed Nov 15, 2023
1 parent a77e8dc commit 78873a8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
11 changes: 10 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"type": "node",
"request": "launch",
Expand All @@ -21,4 +30,4 @@
]
}
]
}
}
9 changes: 4 additions & 5 deletions packages/core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { Fn, createServer, Plugable } from './src/index';
// import { RpcServer } from './src/server';

// const rpc = new RpcServer({});
const rpc = createServer({});

const fn = new Fn({
prefix: ['/api', '/apk'],
const rpc = createServer({
fn: {
prefix: ['/apk', '/aaa'],
},
});
const demo = new Demo({});

rpc.fn('/a', function (a) {
return { a: a };
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ export class Fn extends Plugable {
constructor(cfg?: any) {
super(cfg);

console.dir(this.config);
// console.dir(this.config);

this.name = 'Fn';
if (this.config.prefix === '') {
if (this.prefix === '') {
this.prefix = '/api';
}

console.dir(this.config);
// console.dir(this.config);
}
fn(key, fn) {
// console.dir('=this.config=');
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export class Plugable implements Strategy {
this.app = new Koa();
this.init = [];
this.load = [];
this.prefix = '';
this.prefix = this.config.prefix ? this.config.prefix : '';

this.compose = compose;

// TODO: 此处最好改成mount
Expand Down
23 changes: 15 additions & 8 deletions packages/core/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { bodyParser } from '@koa/bodyparser';
import Koa from 'koa';
import compose from 'koa-compose';
import mount from 'koa-mount';

import { Strategy, log } from './index';
Expand Down Expand Up @@ -145,15 +146,21 @@ export class RpcServer {
console.dir('mount plugin ' + plugin.prefix);
// console.dir(plugin);
// this.app.use(compose([plugin.proxy(), mount(plugin.prefix, plugin.app)]));

if (Array.isArray(plugin.prefix) === true) {
console.dir('prefix is array' + plugin.prefix);
plugin.prefix.forEach((path) => {
console.dir('mount path' + path);
const i = mount(path, plugin.app);
this.app.use(path, i);
});
const that = this.app;
if (Array.isArray(plugin.config.prefix) === true) {
console.dir('prefix is array ' + plugin.config.prefix);

for (const i in plugin.config.prefix) {
const path = plugin.config.prefix[i];
console.dir('mount path = ' + path);
const mw = mount(path, plugin.app);
console.dir(mw);
// console.dir(this);
this.app.use(mw);
}
} else {
console.dir('prefix is string ' + plugin.prefix);

const mw = plugin.prefix === '' ? mount(plugin.app) : mount(plugin.prefix, plugin.app);
this.app.use(mw);
}
Expand Down

0 comments on commit 78873a8

Please sign in to comment.