Skip to content

Commit ca1cad0

Browse files
committed
feat: add backend-mock app
1 parent c58aa26 commit ca1cad0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3421
-736
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dev-dist
1212
yarn.lock
1313
package-lock.json
1414
.VSCodeCounter
15+
**/backend-mock/data
1516

1617
# local env files
1718
.env.local

apps/backend-mock/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# @vben/backend-mock
2+
3+
## Description
4+
5+
Vben Admin Pro 数据mock服务
6+
7+
## Running the app
8+
9+
```bash
10+
# development
11+
$ pnpm run start
12+
13+
# watch mode
14+
$ pnpm run start:dev
15+
16+
# production mode
17+
$ pnpm run start:prod
18+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
apps: [
3+
{
4+
autorestart: true,
5+
cwd: './',
6+
env: {
7+
NODE_ENV: 'production',
8+
},
9+
env_development: {
10+
NODE_ENV: 'development',
11+
},
12+
env_production: {
13+
NODE_ENV: 'production',
14+
},
15+
ignore_watch: ['node_modules', '.logs', 'dist'],
16+
instances: 1,
17+
max_memory_restart: '1G',
18+
name: '@vben/backend-mock',
19+
script: 'node dist/main.js',
20+
watch: false,
21+
},
22+
],
23+
};

apps/backend-mock/http/auth.http

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@port = 5320
2+
@type = application/json
3+
@token = Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MCwicm9sZXMiOlsiYWRtaW4iXSwidXNlcm5hbWUiOiJ2YmVuIiwiaWF0IjoxNzE5ODkwMTEwLCJleHAiOjE3MTk5NzY1MTB9.eyAFsQ2Jk_mAQGvrEL1jF9O6YmLZ_PSYj5aokL6fCuU
4+
POST http://localhost:{{port}}/api/auth/login HTTP/1.1
5+
content-type: {{ type }}
6+
7+
{
8+
"username": "vben",
9+
"password": "123456"
10+
}
11+
12+
13+
###
14+
GET http://localhost:{{port}}/api/auth/getUserInfo HTTP/1.1
15+
content-type: {{ type }}
16+
Authorization: {{ token }}
17+
18+
{
19+
"username": "vben"
20+
}

apps/backend-mock/http/health.http

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@port = 5320
2+
GET http://localhost:{{port}}/api HTTP/1.1
3+
content-type: application/json

apps/backend-mock/nest-cli.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://json.schemastore.org/nest-cli",
3+
"collection": "@nestjs/schematics",
4+
"sourceRoot": "src",
5+
"compilerOptions": {
6+
"assets": ["**/*.yml"],
7+
"watchAssets": true,
8+
"deleteOutDir": true
9+
}
10+
}

apps/backend-mock/package.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "@vben/backend-mock",
3+
"version": "0.0.1",
4+
"description": "",
5+
"private": true,
6+
"license": "MIT",
7+
"author": "",
8+
"scripts": {
9+
"build": "nest build",
10+
"dev": "pnpm run start:dev",
11+
"start:dev": "cross-env NODE_ENV=development DEBUG=true nest start --watch",
12+
"start": "cross-env NODE_ENV=development node dist/main",
13+
"start:prod": "cross-env NODE_ENV=production node dist/main"
14+
},
15+
"dependencies": {
16+
"@nestjs/common": "^10.3.10",
17+
"@nestjs/config": "^3.2.3",
18+
"@nestjs/core": "^10.3.10",
19+
"@nestjs/jwt": "^10.2.0",
20+
"@nestjs/passport": "^10.0.3",
21+
"@nestjs/platform-express": "^10.3.10",
22+
"@nestjs/typeorm": "^10.0.2",
23+
"@types/js-yaml": "^4.0.9",
24+
"bcryptjs": "^2.4.3",
25+
"class-transformer": "^0.5.1",
26+
"class-validator": "^0.14.1",
27+
"cross-env": "^7.0.3",
28+
"joi": "^17.13.3",
29+
"js-yaml": "^4.1.0",
30+
"passport": "^0.7.0",
31+
"passport-jwt": "^4.0.1",
32+
"passport-local": "^1.0.0",
33+
"reflect-metadata": "^0.2.2",
34+
"rxjs": "^7.8.1",
35+
"sqlite3": "^5.1.7",
36+
"typeorm": "^0.3.20"
37+
},
38+
"devDependencies": {
39+
"@nestjs/cli": "^10.3.2",
40+
"@nestjs/schematics": "^10.1.1",
41+
"@types/express": "^4.17.21",
42+
"@types/node": "^20.14.9",
43+
"nodemon": "^3.1.4",
44+
"ts-node": "^10.9.2",
45+
"typescript": "^5.5.3"
46+
}
47+
}

apps/backend-mock/src/app.module.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import configuration from '@/config/index';
2+
import { Module } from '@nestjs/common';
3+
import { ConfigModule } from '@nestjs/config';
4+
import { TypeOrmModule } from '@nestjs/typeorm';
5+
import Joi from 'joi';
6+
7+
import { AuthModule } from './modules/auth/auth.module';
8+
import { DatabaseModule } from './modules/database/database.module';
9+
import { HealthModule } from './modules/health/health.module';
10+
import { UsersModule } from './modules/users/users.module';
11+
12+
@Module({
13+
imports: [
14+
TypeOrmModule.forRoot({
15+
autoLoadEntities: true,
16+
database: 'data/db.sqlite',
17+
synchronize: true,
18+
type: 'sqlite',
19+
}),
20+
ConfigModule.forRoot({
21+
cache: true,
22+
isGlobal: true,
23+
load: [configuration],
24+
validationOptions: {
25+
abortEarly: true,
26+
allowUnknown: true,
27+
},
28+
validationSchema: Joi.object({
29+
NODE_ENV: Joi.string().valid('development', 'production', 'test'),
30+
port: Joi.number(),
31+
}),
32+
}),
33+
HealthModule,
34+
AuthModule,
35+
UsersModule,
36+
DatabaseModule,
37+
],
38+
})
39+
export class AppModule {}

apps/backend-mock/src/config/dev.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
NODE_ENV: development
2+
port: 5320
3+
apiPrefix: /api
4+
jwt:
5+
secret: plonmGN4aSuMVnucrHuhnUoo49Wy
6+
expiresIn: 1d
7+
refreshSecret: 1lonmGN4aSuMVnucrHuhnUoo49Wy
8+
refreshexpiresIn: 7d

apps/backend-mock/src/config/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { readFileSync } from 'node:fs';
2+
import { join } from 'node:path';
3+
import process from 'node:process';
4+
5+
import * as yaml from 'js-yaml';
6+
7+
const configFileNameObj = {
8+
development: 'dev',
9+
production: 'prod',
10+
};
11+
12+
const env = process.env.NODE_ENV;
13+
14+
const configFactory = () => {
15+
return yaml.load(
16+
readFileSync(
17+
join(process.cwd(), 'src', 'config', `${configFileNameObj[env]}.yml`),
18+
'utf8',
19+
),
20+
) as Record<string, any>;
21+
};
22+
23+
export default configFactory;

0 commit comments

Comments
 (0)