首页 前端知识 nodejs轻量级微服务框架

nodejs轻量级微服务框架

2024-07-24 23:07:29 前端知识 前端哥 186 360 我要收藏

框架安装方法:

npm install gzwebsj-router   |.  cnpm install gzwebsj-router

项目目录一览

├── 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

项目作者: gzwebsj@163.com

项目使用说明

框架使用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)

谢谢🙏您的支持,请多多包涵

转载请注明出处或者链接地址:https://www.qianduange.cn//article/14271.html
评论
发布的文章

JSON File 格式详解

2024-08-08 23:08:37

nvm安装node一直没有npm

2024-08-08 23:08:25

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!