glede-server
Advanced tools
| /** | ||
| * @file 服务入口初始化 | ||
| * @author fanchong | ||
| * @date 2024-05-03 | ||
| */ | ||
| import cats from '#/controllers/cat'; | ||
| // modelAs后缀不一定是s, 请查看mongoose文档的集合命名方式, 当然你也可以强制自定义集合名, 这样你就可以使用单数形式的集合名 | ||
| // import modelAs from '#/controllers/modelA'; | ||
| /** | ||
| * 传入Promise为之绑定catch方法并返回,设置打印错误日志 | ||
| * @param p Promise | ||
| * @param errHead 补全日志头部描述 | ||
| * @param level 错误级别 0 error | 1 warn | 2 info | ||
| * @returns 绑定了catch回调的Promise本身 | ||
| */ | ||
| export function CatchExec<T = any>(p: any, errHead = '', level: 0 | 1 | 2 = 0): Promise<T> { | ||
| return p.catch(e => { | ||
| const errMsg = `${errHead} ${e}`; | ||
| if (level === 0) { | ||
| console.error(errMsg); | ||
| } | ||
| if (level === 1) { | ||
| console.warn(errMsg); | ||
| } | ||
| if (level === 2) { | ||
| console.info(errMsg); | ||
| } | ||
| }); | ||
| } | ||
| /** | ||
| * 服务初始化 | ||
| */ | ||
| export function serviceEntry() { | ||
| /** | ||
| * 日志打印工具 | ||
| */ | ||
| global.logger = { | ||
| // 建议把日志打印工具挂载到全局对象上方便使用... | ||
| }; | ||
| /** | ||
| * 传入Promise为之绑定catch方法并返回,设置打印错误日志 | ||
| */ | ||
| global.CatchExec = CatchExec; | ||
| /** | ||
| * mongodb模型 | ||
| */ | ||
| // global.models = mongoose.models; | ||
| global.models = { | ||
| cats, | ||
| // ...你的其他Mongoose模型 | ||
| }; | ||
| } |
+1
-0
@@ -51,1 +51,2 @@ /** | ||
| export * as Redis from 'ioredis'; | ||
| export * as pg from 'pg'; |
+1
-1
| { | ||
| "name": "glede-server", | ||
| "version": "1.1.11", | ||
| "version": "1.1.12-doc.1", | ||
| "description": "Web业务服务器", | ||
@@ -5,0 +5,0 @@ "author": "Perfumere<1061393710@qq.com>", |
+6
-2
@@ -7,5 +7,9 @@ /** | ||
| import { Server, GledeUtil, GledeStaticUtil } from '../index'; | ||
| import { Server, GledeUtil, GledeStaticUtil } from '@/index'; | ||
| import { serviceEntry } from '#/components/service/entry'; | ||
| // import Cat from './controllers/cat'; | ||
| // initialize common utils | ||
| serviceEntry(); | ||
| // const app = Server({ conf: 'tests/configs/app.json' }); | ||
@@ -31,4 +35,4 @@ const app = Server({ conf: 'tests/configs/app-config.ts' }); | ||
| app.addHook('onClose', () => { | ||
| app.addHook('onError', () => { | ||
| console.log('server should be closed'); | ||
| }); |
@@ -47,2 +47,5 @@ /** | ||
| export default Model('cat', CatSchema, CatUtil); | ||
| // 注意⚠️:一定要定义引用后导出, 不然可能存在Model重复定义而报错。这个具体的JS/TS解释器有关。 | ||
| const Cat = Model('cat', CatSchema, CatUtil); | ||
| export default Cat; |
@@ -8,3 +8,3 @@ /** | ||
| import { Model, GledeStaticUtil } from 'glede-server'; | ||
| import User from '@/controllers/user'; | ||
| import User from '#/controllers/user'; | ||
| import type { LuaRedis } from '@/types/redis-lua'; | ||
@@ -11,0 +11,0 @@ |
@@ -8,3 +8,3 @@ /** | ||
| import { Transaction } from 'glede-server'; | ||
| import Cat from '@/controllers/cat'; | ||
| import Cat from '#/controllers/cat'; | ||
@@ -11,0 +11,0 @@ /** |
+4
-2
@@ -10,5 +10,7 @@ { | ||
| "paths": { | ||
| "@/*": ["./*"] | ||
| } | ||
| "@/*": ["./*"], | ||
| "#/*": ["./tests/*"] | ||
| }, | ||
| "baseUrl": "." | ||
| } | ||
| } |
@@ -15,4 +15,4 @@ /** | ||
| export * as mongoose from 'mongoose'; | ||
| export * as pg from 'pg'; | ||
| interface GledeThis { | ||
@@ -510,3 +510,3 @@ /** 请求方法 */ | ||
| */ | ||
| export function Transaction(func: (session: ClientSession) => void | Promise<void>): Promise<void>; | ||
| export function Transaction(func: (session: ClientSession) => any): Promise<void>; | ||
@@ -513,0 +513,0 @@ interface GledeTokenUtil { |
| { | ||
| "skipLibCheck": true, | ||
| "compilerOptions": { | ||
| "target": "ESNext", | ||
| "experimentalDecorators": true, | ||
| "module": "NodeNext", | ||
| "moduleResolution": "NodeNext", | ||
| "resolveJsonModule": true, | ||
| "paths": { | ||
| "@/*": ["./*"] | ||
| } | ||
| } | ||
| } |
| /// <reference types="glede-server/types" /> |
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
257182
29.13%4470
1.06%519
3.18%56
-1.75%3
50%