forked from vbenjs/vue-vben-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use simpler nitro instead of nestjs to implement mock service
- Loading branch information
Showing
122 changed files
with
2,575 additions
and
2,986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ dist-ssr | |
dist.zip | ||
dist.tar | ||
dist.war | ||
.nitro | ||
.output | ||
*-dist.zip | ||
*-dist.tar | ||
*-dist.war | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ node_modules | |
.nvmrc | ||
coverage | ||
CODEOWNERS | ||
.nitro | ||
.output | ||
|
||
|
||
**/*.svg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PORT=5320 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default eventHandler((event) => { | ||
const { status } = getQuery(event); | ||
setResponseStatus(event, Number(status)); | ||
return useResponseError(`${status}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default defineEventHandler(() => 'Test get handler'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default defineEventHandler(() => 'Test post handler'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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 file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { NitroErrorHandler } from 'nitropack'; | ||
|
||
const errorHandler: NitroErrorHandler = function (error, event) { | ||
event.res.end(`[error handler] ${error.stack}`); | ||
}; | ||
|
||
export default errorHandler; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import errorHandler from './error'; | ||
|
||
export default defineNitroConfig({ | ||
devErrorHandler: errorHandler, | ||
errorHandler: '~/error', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default defineEventHandler(() => { | ||
return ` | ||
<h1>Hello Vben Admin</h1> | ||
<h2>Mock service is starting</h2> | ||
<ul> | ||
<li><a href="/api/user">/api/user/info</a></li> | ||
<li><a href="/api/menu">/api/menu/all</a></li> | ||
<li><a href="/api/auth/codes">/api/auth/codes</a></li> | ||
<li><a href="/api/auth/login">/api/auth/login</a></li> | ||
</ul> | ||
`; | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
apps/backend-mock/src/core/filter/http-exception.filter.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.