Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
张婷
forProjectBaseTemp
Commits
99874516
Commit
99874516
authored
1 year ago
by
vben
Browse files
Options
Download
Email Patches
Plain Diff
feat: use simpler nitro instead of nestjs to implement mock service
parent
9ec91ac1
Changes
121
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
94 additions
and
101 deletions
+94
-101
.gitignore
.gitignore
+2
-0
.prettierignore
.prettierignore
+2
-0
.vscode/settings.json
.vscode/settings.json
+2
-1
apps/backend-mock/.env
apps/backend-mock/.env
+1
-0
apps/backend-mock/README.md
apps/backend-mock/README.md
+1
-4
apps/backend-mock/api/auth/codes.ts
apps/backend-mock/api/auth/codes.ts
+15
-0
apps/backend-mock/api/auth/login.post.ts
apps/backend-mock/api/auth/login.post.ts
+20
-0
apps/backend-mock/api/menu/all.ts
apps/backend-mock/api/menu/all.ts
+14
-0
apps/backend-mock/api/status.ts
apps/backend-mock/api/status.ts
+5
-0
apps/backend-mock/api/test.get.ts
apps/backend-mock/api/test.get.ts
+1
-0
apps/backend-mock/api/test.post.ts
apps/backend-mock/api/test.post.ts
+1
-0
apps/backend-mock/api/user/info.ts
apps/backend-mock/api/user/info.ts
+14
-0
apps/backend-mock/ecosystem.config.cjs
apps/backend-mock/ecosystem.config.cjs
+0
-23
apps/backend-mock/error.ts
apps/backend-mock/error.ts
+7
-0
apps/backend-mock/http/auth.http
apps/backend-mock/http/auth.http
+0
-20
apps/backend-mock/http/health.http
apps/backend-mock/http/health.http
+0
-3
apps/backend-mock/http/menu.http
apps/backend-mock/http/menu.http
+0
-6
apps/backend-mock/nest-cli.json
apps/backend-mock/nest-cli.json
+0
-10
apps/backend-mock/nitro.config.ts
apps/backend-mock/nitro.config.ts
+6
-0
apps/backend-mock/package.json
apps/backend-mock/package.json
+3
-34
No files found.
.gitignore
View file @
99874516
...
...
@@ -5,6 +5,8 @@ dist-ssr
dist.zip
dist.tar
dist.war
.nitro
.output
*-dist.zip
*-dist.tar
*-dist.war
...
...
This diff is collapsed.
Click to expand it.
.prettierignore
View file @
99874516
...
...
@@ -6,6 +6,8 @@ node_modules
.nvmrc
coverage
CODEOWNERS
.nitro
.output
**/*.svg
...
...
This diff is collapsed.
Click to expand it.
.vscode/settings.json
View file @
99874516
...
...
@@ -191,5 +191,6 @@
"tailwind.config.mjs"
:
"postcss.*"
},
"commentTranslate.hover.enabled"
:
true
,
"i18n-ally.keystyle"
:
"nested"
"i18n-ally.keystyle"
:
"nested"
,
"commentTranslate.multiLineMerge"
:
true
}
This diff is collapsed.
Click to expand it.
apps/backend-mock/.env
0 → 100644
View file @
99874516
PORT=5320
This diff is collapsed.
Click to expand it.
apps/backend-mock/README.md
View file @
99874516
...
...
@@ -10,9 +10,6 @@ Vben Admin 数据 mock 服务,没有对接任何的数据库,所有数据都
# development
$
pnpm run start
# watch mode
$
pnpm run start:dev
# production mode
$
pnpm run
start:pro
d
$
pnpm run
buil
d
```
This diff is collapsed.
Click to expand it.
apps/backend-mock/api/auth/codes.ts
0 → 100644
View file @
99874516
export
default
eventHandler
((
event
)
=>
{
const
token
=
getHeader
(
event
,
'
Authorization
'
);
if
(
!
token
)
{
setResponseStatus
(
event
,
401
);
return
useResponseError
(
'
UnauthorizedException
'
,
'
Unauthorized Exception
'
);
}
const
username
=
Buffer
.
from
(
token
,
'
base64
'
).
toString
(
'
utf8
'
);
const
codes
=
MOCK_CODES
.
find
((
item
)
=>
item
.
username
===
username
)?.
codes
??
[];
return
useResponseSuccess
(
codes
);
});
This diff is collapsed.
Click to expand it.
apps/backend-mock/api/auth/login.post.ts
0 → 100644
View file @
99874516
export
default
defineEventHandler
(
async
(
event
)
=>
{
const
{
password
,
username
}
=
await
readBody
(
event
);
const
findUser
=
MOCK_USERS
.
find
(
(
item
)
=>
item
.
username
===
username
&&
item
.
password
===
password
,
);
if
(
!
findUser
)
{
setResponseStatus
(
event
,
403
);
return
useResponseError
(
'
UnauthorizedException
'
,
'
用户名或密码错误
'
);
}
const
accessToken
=
Buffer
.
from
(
username
).
toString
(
'
base64
'
);
return
useResponseSuccess
({
accessToken
,
// TODO: refresh token
refreshToken
:
accessToken
,
});
});
This diff is collapsed.
Click to expand it.
apps/backend-mock/api/menu/all.ts
0 → 100644
View file @
99874516
export
default
eventHandler
((
event
)
=>
{
const
token
=
getHeader
(
event
,
'
Authorization
'
);
if
(
!
token
)
{
setResponseStatus
(
event
,
401
);
return
useResponseError
(
'
UnauthorizedException
'
,
'
Unauthorized Exception
'
);
}
const
username
=
Buffer
.
from
(
token
,
'
base64
'
).
toString
(
'
utf8
'
);
const
menus
=
MOCK_MENUS
.
find
((
item
)
=>
item
.
username
===
username
)?.
menus
??
[];
return
useResponseSuccess
(
menus
);
});
This diff is collapsed.
Click to expand it.
apps/backend-mock/api/status.ts
0 → 100644
View file @
99874516
export
default
eventHandler
((
event
)
=>
{
const
{
status
}
=
getQuery
(
event
);
setResponseStatus
(
event
,
Number
(
status
));
return
useResponseError
(
`
${
status
}
`
);
});
This diff is collapsed.
Click to expand it.
apps/backend-mock/api/test.get.ts
0 → 100644
View file @
99874516
export
default
defineEventHandler
(()
=>
'
Test get handler
'
);
This diff is collapsed.
Click to expand it.
apps/backend-mock/api/test.post.ts
0 → 100644
View file @
99874516
export
default
defineEventHandler
(()
=>
'
Test post handler
'
);
This diff is collapsed.
Click to expand it.
apps/backend-mock/api/user/info.ts
0 → 100644
View file @
99874516
export
default
eventHandler
((
event
)
=>
{
const
token
=
getHeader
(
event
,
'
Authorization
'
);
if
(
!
token
)
{
setResponseStatus
(
event
,
401
);
return
useResponseError
(
'
UnauthorizedException
'
,
'
Unauthorized Exception
'
);
}
const
username
=
Buffer
.
from
(
token
,
'
base64
'
).
toString
(
'
utf8
'
);
const
user
=
MOCK_USERS
.
find
((
item
)
=>
item
.
username
===
username
);
const
{
password
:
_pwd
,
...
userInfo
}
=
user
;
return
useResponseSuccess
(
userInfo
);
});
This diff is collapsed.
Click to expand it.
apps/backend-mock/ecosystem.config.cjs
deleted
100644 → 0
View file @
9ec91ac1
module
.
exports
=
{
apps
:
[
{
autorestart
:
true
,
cwd
:
'
./
'
,
env
:
{
NODE_ENV
:
'
production
'
,
},
env_development
:
{
NODE_ENV
:
'
development
'
,
},
env_production
:
{
NODE_ENV
:
'
production
'
,
},
ignore_watch
:
[
'
node_modules
'
,
'
.logs
'
,
'
dist
'
],
instances
:
1
,
max_memory_restart
:
'
1G
'
,
name
:
'
@vben/backend-mock
'
,
script
:
'
node dist/main.js
'
,
watch
:
false
,
},
],
};
This diff is collapsed.
Click to expand it.
apps/backend-mock/error.ts
0 → 100644
View file @
99874516
import
type
{
NitroErrorHandler
}
from
'
nitropack
'
;
const
errorHandler
:
NitroErrorHandler
=
function
(
error
,
event
)
{
event
.
res
.
end
(
`[error handler]
${
error
.
stack
}
`
);
};
export
default
errorHandler
;
This diff is collapsed.
Click to expand it.
apps/backend-mock/http/auth.http
deleted
100644 → 0
View file @
9ec91ac1
@port = 5320
@type = application/json
@token = Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MCwicm9sZXMiOlsiYWRtaW4iXSwidXNlcm5hbWUiOiJ2YmVuIiwiaWF0IjoxNzE5ODkwMTEwLCJleHAiOjE3MTk5NzY1MTB9.eyAFsQ2Jk_mAQGvrEL1jF9O6YmLZ_PSYj5aokL6fCuU
POST http://localhost:{{port}}/api/auth/login HTTP/1.1
content-type: {{ type }}
{
"username": "vben",
"password": "123456"
}
###
GET http://localhost:{{port}}/api/auth/getUserInfo HTTP/1.1
content-type: {{ type }}
Authorization: {{ token }}
{
"username": "vben"
}
This diff is collapsed.
Click to expand it.
apps/backend-mock/http/health.http
deleted
100644 → 0
View file @
9ec91ac1
@port = 5320
GET http://localhost:{{port}}/api HTTP/1.1
content-type: application/json
This diff is collapsed.
Click to expand it.
apps/backend-mock/http/menu.http
deleted
100644 → 0
View file @
9ec91ac1
@port = 5320
@type = application/json
@token = Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MCwicm9sZXMiOlsiYWRtaW4iXSwidXNlcm5hbWUiOiJ2YmVuIiwiaWF0IjoxNzE5ODkwMTEwLCJleHAiOjE3MTk5NzY1MTB9.eyAFsQ2Jk_mAQGvrEL1jF9O6YmLZ_PSYj5aokL6fCuU
GET http://localhost:{{port}}/api/menu/getAll HTTP/1.1
content-type: {{ type }}
Authorization: {{ token }}
This diff is collapsed.
Click to expand it.
apps/backend-mock/nest-cli.json
deleted
100644 → 0
View file @
9ec91ac1
{
"$schema"
:
"https://json.schemastore.org/nest-cli"
,
"collection"
:
"@nestjs/schematics"
,
"sourceRoot"
:
"src"
,
"compilerOptions"
:
{
"assets"
:
[
"**/*.yml"
,
"**/*.json"
],
"watchAssets"
:
true
,
"deleteOutDir"
:
true
}
}
This diff is collapsed.
Click to expand it.
apps/backend-mock/nitro.config.ts
0 → 100644
View file @
99874516
import
errorHandler
from
'
./error
'
;
export
default
defineNitroConfig
({
devErrorHandler
:
errorHandler
,
errorHandler
:
'
~/error
'
,
});
This diff is collapsed.
Click to expand it.
apps/backend-mock/package.json
View file @
99874516
...
...
@@ -6,41 +6,10 @@
"license"
:
"MIT"
,
"author"
:
""
,
"scripts"
:
{
"build"
:
"nest build"
,
"dev"
:
"pnpm run start:dev"
,
"start"
:
"cross-env NODE_ENV=development node dist/main"
,
"start:dev"
:
"cross-env NODE_ENV=development DEBUG=true nest start --watch"
,
"start:prod"
:
"nest build && cross-env NODE_ENV=production node dist/main"
"start"
:
"nitro dev"
,
"build"
:
"nitro build"
},
"dependencies"
:
{
"@nestjs/common"
:
"^10.3.10"
,
"@nestjs/config"
:
"^3.2.3"
,
"@nestjs/core"
:
"^10.3.10"
,
"@nestjs/jwt"
:
"^10.2.0"
,
"@nestjs/passport"
:
"^10.0.3"
,
"@nestjs/platform-express"
:
"^10.3.10"
,
"@types/js-yaml"
:
"^4.0.9"
,
"bcryptjs"
:
"^2.4.3"
,
"class-transformer"
:
"^0.5.1"
,
"class-validator"
:
"^0.14.1"
,
"cross-env"
:
"^7.0.3"
,
"joi"
:
"^17.13.3"
,
"js-yaml"
:
"^4.1.0"
,
"mockjs"
:
"^1.1.0"
,
"passport"
:
"^0.7.0"
,
"passport-jwt"
:
"^4.0.1"
,
"passport-local"
:
"^1.0.0"
,
"reflect-metadata"
:
"^0.2.2"
,
"rxjs"
:
"^7.8.1"
},
"devDependencies"
:
{
"@nestjs/cli"
:
"^10.4.2"
,
"@nestjs/schematics"
:
"^10.1.2"
,
"@types/express"
:
"^4.17.21"
,
"@types/mockjs"
:
"^1.0.10"
,
"@types/node"
:
"^20.14.11"
,
"nodemon"
:
"^3.1.4"
,
"ts-node"
:
"^10.9.2"
,
"typescript"
:
"^5.5.3"
"nitropack"
:
"latest"
}
}
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
5
…
7
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment