Skip to content

Commit

Permalink
feat(:sip): add dotenv , add .env file;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Mar 29, 2021
1 parent 0107f03 commit 098ba91
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DB=lesstest
DB_URI=mongodb://localhost:27017
DB_POOL_LIMIT=10
SERVER_SALT=abcdefg1234567!@#$%^&sadfqwef&*^*#!@^
SUPER_ADMIN=less
SUPER_ADMIN_PASSWORD=less123
LOG_LEVEL=debug
7 changes: 7 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DB=lessdb
DB_URI=mongodb://localhost:27017
DB_POOL_LIMIT=10
SERVER_SALT=abcdefg1234567!@#$%^&sadfqwef&*^*#!@^
SUPER_ADMIN=less
SUPER_ADMIN_PASSWORD=less123
LOG_LEVEL=info
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ dist

upload
data/*
tmp
tmp

.env
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ less-framework 让你开箱即用 less-api, 内置基于角色的权限控制

真正实现,服务端超低代码,极速上线应用。

- 基于 [less-api](https://github.com/Maslow/less-api) 打造服务端低代码框架
如果你熟悉微信云开发,那 less-framework 就是让你拥有自己的、可独立部署的、开源的、可控的云开发框架。

- 基于 [less-api](https://github.com/Maslow/less-api) 打造的服务端低代码框架
- less-framework 集成了 RBAC、文件上传下载、用户授权,开箱即用,5分钟上线应用
- 前端可使用 [less-api-client](https://github.com/Maslow/less-api-client-js) “直连”数据库,无需与服务端对接口
- 另有 Flutter SDK [less-api-client](https://github.com/Maslow/less-api-client-dart),快速上线移动端应用
Expand All @@ -23,7 +25,10 @@ docker run -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=less -e MONGO_INITDB_ROO
```

### 配置数据库 (MongoDb)
`/src/config.ts`

>【推荐】将 .env.development 拷贝并重命名为 .env,编辑里面的环境变量
>【不推荐】或直接修改 `/src/config.ts` 相应配置
### 初始化应用的基础数据
> 初始化管理员、角色、权限、访问规则
Expand All @@ -32,8 +37,30 @@ npm run init
```

### 运行

```sh
# 编译
npm run build
#运行
npm start
```
```

> 开发环境可自动编译 ts 代码
```sh
npm run watch
```

> 也可使用 pm2 来运行应用
```sh
pm2 run
```

## TODO

- 支持云函数的导入导出(less-admin),可以更好的复用、备份、迁移云函数
- 支持云函数市场,可以更好的分享、复用云函数
- 支持云函数版本管理,可发布版本、历史版本、回滚版本
- 支持 MongoFileStorage,默认将文件存储至 Mongo GridFS(可以更好的利用 Mongo 的分布式、弹性扩展优势)
- 支持阿里云 OSS 存储, AliOssStorage
- 支持在线安装 npm 预设包,可配置云函数执行环境依赖
- 支持 less-api watch() 功能,实现长连接数据流推送
- 支持本地云函数执行环境,一键调试,一键发版
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"axios": "^0.21.1",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"fs-extra": "^9.1.0",
"less-api": "^1.3.5",
Expand All @@ -38,6 +39,7 @@
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"@commitlint/prompt-cli": "^12.0.1",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.11",
"@types/fs-extra": "^9.0.8",
"@types/mongodb": "^3.6.10",
Expand Down
7 changes: 5 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

import * as path from 'path'
import * as dotenv from 'dotenv'
dotenv.config()

export default class Config {
static get db() {
return {
database: process.env['DB'] ?? 'less_framework',
uri: process.env['DB_URI'] ?? 'mongodb://localhost:27017',
poolSize: (process.env['DB_POOL_LIMIT'] ?? 100) as number,

// for mysql:
// user: process.env['DB_USER'] ?? "root",
// password: process.env['DB_PASSWORD'] ?? "kissme",
// host: process.env['DB_HOST'] ?? "127.0.0.1",
Expand All @@ -25,7 +28,7 @@ export default class Config {

// 初始化第一个管理员的密码
static get SUPER_ADMIN_PASSWORD(): string {
return process.env['SUPER_ADMIN_PASSWORD'] ?? 'less'
return process.env['SUPER_ADMIN_PASSWORD'] ?? 'less123'
}

// 本地上传文件存储目录
Expand Down

0 comments on commit 098ba91

Please sign in to comment.