-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,501 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# @tomrpc/core | ||
|
||
## 1.0.0 | ||
|
||
### Major Changes | ||
|
||
- v0.1.1 | ||
|
||
## 0.1.1 | ||
|
||
### Patch Changes | ||
|
||
- init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# @tomrpc/core | ||
|
||
## create | ||
|
||
```js | ||
const rpc = createServer({ | ||
beforeOne: function (ctx: any, key: string) { | ||
console.log(ctx.path); | ||
console.log(ctx.method); | ||
console.log('beforeOne key=' + key); | ||
}, | ||
}); | ||
|
||
``` | ||
|
||
## lifecyle | ||
|
||
- beforeAll(中间件) | ||
- beforeEach(中间件) | ||
- beforeOne(普通函数) | ||
- 函数执行 | ||
- afterOne(普通函数) | ||
- afterEach(中间件) | ||
- afterAll(中间件) | ||
|
||
## example | ||
|
||
```js | ||
import { createServer } from '@tomrpc/core'; | ||
|
||
const rpc = createServer({ | ||
beforeOne: function (ctx: any, key: string) { | ||
console.log(ctx.path); | ||
console.log(ctx.method); | ||
console.log('beforeOne key=' + key); | ||
}, | ||
}); | ||
|
||
rpc.fn('a', (a: string) => { | ||
return a; | ||
}); | ||
|
||
rpc.fn('a.a', (a: string, ctx: any) => { | ||
// console.dir(ctx); | ||
if (ctx.method === 'POST') { | ||
console.dir('post'); | ||
return { | ||
a: a, | ||
// b: b, | ||
}; | ||
} else { | ||
console.dir('get' + ctx.method); | ||
return a; | ||
} | ||
}); | ||
|
||
rpc.fn('b', () => { | ||
console.dir('test b'); | ||
}); | ||
|
||
rpc.add({ | ||
c: (a: string) => { | ||
return a; | ||
}, | ||
a: function (a: string, b: string) { | ||
return `${this.path} , ${a} c2 ${b}`; | ||
}, | ||
}); | ||
|
||
// https://bobbyhadz.com/blog/typescript-no-overload-matches-this-call | ||
// rpc.dump(); | ||
// console.dir(rpc.dump()); | ||
|
||
// rpc.mount(); | ||
|
||
rpc.listen(3000); | ||
``` | ||
|
||
|
||
const app = new Koa() | ||
|
||
|
||
const app1 = new Koa() | ||
const app2 = new Koa() | ||
const app3 = new Koa() | ||
|
||
app.mount(app1.prefix,fn) | ||
app.mount(app2.prefix,view) | ||
app.mount(app3.prefix,static) | ||
|
||
=> | ||
|
||
const app = new Koa() | ||
|
||
|
||
|
||
app.plugin({ | ||
prefix, | ||
fn | ||
}) | ||
|
||
return fn={ | ||
name='fn' | ||
init:[], | ||
load:[] | ||
|
||
} | ||
app.plugin(app2.prefix,view) | ||
app.plugin(app3.prefix,static) |
Oops, something went wrong.