1.0.33 • Published 4 months ago

typescript-boot v1.0.33

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

typescript-boot

这是一个可以帮助你用typescript快速开发后端API接口服务的脚手架。同时支持通过注解生成完全可供前端同学开发参考的在线接口文档。

里面提供了包括session会话管理、权限管理、日志管理的开箱即用功能,同时又支持完全自定义这些管理器。

还提供了方便操作数据库的方式,支持各种数据库(支持mysql、达梦数据库、其他数据库也很方便可以实现)。对数据库的操作支持对象映射。

以下是一个简单示例:

更多功能可以参考这个完整的、可运行的示例:https://github.com/seeksdream/typescript-boot-demo

1,首先安装依赖

npm install typescript-boot

2,编写代码

// 首先,编写一个接口服务:

@apiDoc('权限认证') // 描述服务名称
@apiPermission(NoRequiredPermission) // 设置访问当前接口服务的前置条件,如无需登录、需要登录、仅限指定角色登录等
@apiPath('/account') //设置访问此服务下的接口的前缀路径
export default class AccountService extends BaseService{
  @apiDoc('登录')
  @apiReturn('会话token(string)') // 描述返回结果中数据内容
  @apiPath('login') //结合服务路径/account,最终此接口的访问路径为:http://localhost:端口/account/login
  async login(
    @apiParamFromBody('登录账号') account:string, // 从body中获取account属性,并描述account的含义为:登录账号
    @apiParamFromBody('登录密码(MD5)') password:string, // 从body中获取password属性,并描述password的含义为:登录密码
    @apiRequest() req
  ) {
    // TODO 实现接口内容
    const token = '';
    return this.success(token);
  }
}

// 然后,在你的主程序中通过以下代码发布接口服务并启动

import 'reflect-metadata';
import {SeeksWebServer} from 'typescript-boot';
const port = 3333;
const server = new SeeksWebServer(port);
server.publishService(new AccountService()); // 注册一个api服务
server.start(); // 启动服务,然后就可以调用接口了

此刻,你的接口就可以被调用了。

同时,你还可以同通过以下链接来查看接口文档:

http://localhost:端口/typescript-boot

简单示例效果图

1.0.33

4 months ago

1.0.32

4 months ago

1.0.29

5 months ago

1.0.31

5 months ago

1.0.30

5 months ago

1.0.19

5 months ago

1.0.22

5 months ago

1.0.21

5 months ago

1.0.20

5 months ago

1.0.26

5 months ago

1.0.25

5 months ago

1.0.24

5 months ago

1.0.23

5 months ago

1.0.18

7 months ago

1.0.17

8 months ago

1.0.16

8 months ago

1.0.15

8 months ago

1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago