粗体框架
说明
最低的,高的 表演者 中间软件 临 时 15 启发基于功能的微观框架尽可能地不复杂地构建,主要针对那些想了解他们使用的所有销售商的开发者.
所需资源
- 节点: 22
- @ chubbyts/ chubbyts-dic-types (英语): ^ 2.4.0 (中文(简体) )
- @chubbyts/chubbyts-http-error (英语): ^3.6.0 (中文(简体) )
- @ hubbyts/ chubbyts- http- types: ^ 4.1.0 (中文(简体) )
- @ chubbyts/ chubbyts-log-类型: ^ 3. 4.0 (中文(简体) )
- @ chubbyts/ chubbyts-可推-tror: ^ 2.4.0 (中文(简体) )
安装
穿过 国家预防机制 作为 @ chubbyts/ chubbyts-框架。 。 。 .
npm i \
@chubbyts/chubbyts-framework-router-path-to-regexp@^4.1.1 \
@chubbyts/chubbyts-framework@^4.2.0 \
@chubbyts/chubbyts-http@^3.1.0
使用量
import { createPathToRegexpMatch }
from '@chubbyts/chubbyts-framework-router-path-to-regexp/path-to-regexp-router';
import { createResponseFactory, createBodyFactory } from '@chubbyts/chubbyts-http/message-factory';
import { createApplication } from '@chubbyts/chubbyts-framework/application';
import { createErrorMiddleware }
from '@chubbyts/chubbyts-framework/middleware/error-middleware';
import { createRouteMatcherMiddleware }
from '@chubbyts/chubbyts-framework/middleware/route-matcher-middleware';
import { createGetRoute } from '@chubbyts/chubbyts-framework/router/route';
import { createRoutesByName } from '@chubbyts/chubbyts-framework/router/routes-by-name';
const bodyFactory = createBodyFactory();
const responseFactory = createResponseFactory(bodyFactory);
const app = createApplication([
createErrorMiddleware(responseFactory, bodyFactory, true),
createRouteMatcherMiddleware(
createPathToRegexpMatch(
createRoutesByName([
createGetRoute<{ name: string }>({
path: '/hello/:name',
name: 'hello',
handler: async (serverRequest) => {
const response = responseFactory(200);
return {
...response,
headers: { ...response.headers, 'content-type': ['text/plain'] },
body: bodyFactory(`Hello, ${serverRequest.attributes.name}`),
};
},
}),
]),
),
),
]);
应用程序构建器
周围的外表 createApplication 编号 : createErrorMiddleware 编号 : createRouteMatcherMiddleware 编号 : createRoute 编号 :
createGroup:纯结构糖,返回的处理器是同一种中间器件管与同一种管
明确组成:先出错中件,后出app中件,再出路由匹配器中件.
第一个论点涉及所有依附关系(ApplicationBuilderDependencies),第二个应用中间软件
(如果没有空阵列).
import { createPathToRegexpMatch as createMatch }
from '@chubbyts/chubbyts-framework-router-path-to-regexp/path-to-regexp-router';
import { createResponseFactory, createBodyFactory } from '@chubbyts/chubbyts-http/message-factory';
import { createApplicationBuilder } from '@chubbyts/chubbyts-framework/facade';
const bodyFactory = createBodyFactory();
const responseFactory = createResponseFactory(bodyFactory);
const application = createApplicationBuilder(
{
createMatch,
responseFactory,
bodyFactory,
// optional: debug, logger, mapToHttpError, createGeneratePath, createGenerateUrl
},
[corsMiddleware],
)
.get('/ping', 'ping', pingHandler)
.get('/openapi', 'openapi', openApiHandler)
.group('/api/pets', [acceptNegotiationMiddleware, apiErrorMiddleware], (pets) =>
pets
.get('', 'pet_list', petListHandler)
.post('', 'pet_create', [contentTypeNegotiationMiddleware], petCreateHandler)
.get('/:id', 'pet_read', petReadHandler)
.put('/:id', 'pet_update', [contentTypeNegotiationMiddleware], petUpdateHandler)
.delete('/:id', 'pet_delete', petDeleteHandler),
)
.build();
服务器
节点
通过标准节点运行应用程序 http 执行 .
npm i @chubbyts/chubbyts-http-node@^1.0.0
检查 使用量 节.
uWebSockets (中文(简体) )
通过 uWebSockets http 执行运行应用程序 .
npm i @chubbyts/chubbyts-http-uwebsockets@^1.0.0
检查 使用量 节.
汉德勒/中件
- 页面存档备份,存于互联网档案馆 @chubbyts/chubbyts-http-api
- @chubbyts/chubbyts-http-cors (英语)
- @chubbyts/chubbyts-http-multip
- @chubbyts/chubbyts-http-oidc (中文(简体) )
- @chubbyts/chubbyts-http-rate-limit 页面存档备份,存于互联网档案馆
- @chubbyts/chubbyts-http-static-文件
- @chubbyts/chubbyts-http-受托代理
斯凯莱通
版权
2026 道米尼克·佐格(英语: