gzwebsj-router
v0.0.1
Published
轻量级微服务 @ Email://[email protected]
Downloads
2
Readme
项目目录一览
├── README.md
├── dist
│ ├── index.js
│ ├── router
│ │ ├── index.js
│ │ ├── router.js
│ │ ├── router_event
│ │ │ └── event.js
│ │ ├── router_exception
│ │ │ └── exception.js
│ │ └── router_utils
│ │ └── index.js
│ └── utils
│ ├── index.js
│ └── types
│ └── index.js
├── index.d.ts
├── index.js
├── index.ts
├── package-lock.json
├── package.json
├── router
│ ├── index.js
│ ├── index.ts
│ ├── router.js
│ ├── router.ts
│ ├── router_event
│ │ ├── event.js
│ │ ├── event.ts
│ │ ├── index.d.js
│ │ └── index.d.ts
│ ├── router_exception
│ │ ├── exception.ts
│ │ └── index.d.ts
│ └── router_utils
│ ├── index.js
│ └── index.ts
├── test
├── tsconfig.json
└── utils
├── index.js
├── index.ts
└── types
├── index.js
└── index.ts
项目简介
项目名称:gzwebsj-router
项目版本:v0.0.1
项目作者: [email protected]
项目使用说明
框架使用nodejs HttpServer2+架构,轻量级的微服务框架!
router_event 事件监听器
主指针函数:
ROUTER_EVENT
handler(method: string, path: string, req: Http2ServerRequest, res: Http2ServerResponse, d: object, callback: (val: any, d: object, cb: () => {}, req: Http2ServerRequest, res: Http2ServerResponse) => {}): Promise<object>
进程监听器和事件监听器:
ROUTER_EVENT
addListener(event_name: string, router_name: string, option: { timeout: number; callback: (...args: any[]) => void}): any
事件钩子
ROUTER_EVENT
eventHook(event_name: string, request: Http2ServerRequest, response: Http2ServerResponse, option: { hook_name: string; data: object; callback: (...args: any[]) => void }): any
路由标示
ROUTER_EVENT
async signal(url: string, signal: AbortSignal): Promise<any>
router 主函数
路由初始化监听器
ROUTER
router_initListener(host: string, port: number, req: Http2ServerRequest): Promise<object>
路由监听器
ROUTER
router_Listener(req: Http2ServerRequest): void
路由跨域
ROUTER
setAccess(response: Http2ServerResponse): void
路由
ROUTER
router(method: string, url: string, URL: string, req: Http2ServerRequest, resp: Http2ServerResponse, data: object): any
使用实例
const http = require("http")
import { Http2ServerRequest, Http2ServerResponse } from 'http2';
const path = require("path")
let o : string = path.normalize('./router');
import ROUTER from './router';
import { ROUTER_EVENT } from './router/router_event/event';
const routers = new ROUTER();
const testevent = new ROUTER_EVENT()
const testrouter = (url: string, req: Http2ServerRequest, res: Http2ServerResponse) => {
const data: object = {
'msg': (() => {
return 'success';
})(),
'code': (() => {
return 200;
})(),
'data': (() => {
return [{}]
})()
}
routers.router('get', url, '/api/home', req, res, data)
testevent.addListener("api_home", url, { timeout: 1000, callback() { } })
testevent.eventHook("api_home", req, res, { hook_name: 'api_hook', data: data, callback() { } })
}
http.createServer((req: Http2ServerRequest, res: Http2ServerResponse)=>{
let url = routers.pathname(req);
testrouter(url,req,res);
}).listen(80)
如果发现debug
联系邮箱: [email protected]