# typeorm-demo **Repository Path**: flwwsg/typeorm-demo ## Basic Information - **Project Name**: typeorm-demo - **Description**: typeorm服务端基础模板 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2024-12-25 - **Last Updated**: 2024-12-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Awesome Project templete Build with TypeORM ## 项目整体文件说明 - `config`配置文件目录 - `appconfig.ts`默认项目配置文件(包含typeorm配置、jwt配置、加密配置、服务配置) - `controllers`控制器目录 - `entity`实体清单目录 - `http`REST Client接口测试文件目录 - `interceptors`拦截器目录 - `middlewares`自定义中间件目录 - `service`业务逻辑存放目录 - `types`定义的数据类型目录 - `utils`公共方法目录 - `index.ts`项目入口 - `server.ts`项目服务 ## 如何使用 - Run `npm install` command - Config the `appconfig.ts` file - Run `npm run serve` command ## 全局中间与件拦截器的执行顺序 ```ts // 1.服务启动 server is running: http://localhost:3000 // 2.@Middleware({ type: 'before' }) **********RequestMiddleware************ // 3.接口方法执行 request.body: { username: '小明', password: 'VrnxVL/p+wPGY9G5ym/BVg==' } // 4.@Interceptor() **********GlobalInterceptor************ action.request.body: { username: '小明', password: 'VrnxVL/p+wPGY9G5ym/BVg==' } action.response.body: undefined // result表示控制器中返回的数据 result: { code: 200, data: null, message: '登录成功' } // 5.@Middleware({ type: 'after' }) **********ResponseMiddleware************ [OK] /api/private/v1/user/login ``` 执行顺序:前置中间件-->方法接口-->全局拦截器-->局部拦截器-->后置中间件。 由此可以知道,拦截器并不影响接口方法的执行,仅能对响应数据结果进行处理。因此,前置数据校验使用前置中间件 即可。并由`context.response.body = {}`设置返回结果。