2023-02-24 16:53:44 +08:00

52 lines
1.3 KiB
TypeScript

import { MockHandler } from 'vite-plugin-mock-server'
type UserModel = {
username: string;
password: string;
avatar: string;
}
type LoginUserModel = {
token: string;
user: UserModel;
}
const loginUserList: LoginUserModel[] = []
const userMock: MockHandler[] = [
{
pattern: '/api/user/login',
method:'POST',
handle: (req, res) => {
const data = { code: 1 }
res.end(JSON.stringify(data))
}
},
{
pattern: '/api/test1/*',
handle: (req, res) => {
res.end('Hello world!' + req.url)
}
},
{
pattern: '/api/test1/users/{userId}',
handle: (req, res, pathVars) => {
const data = {
url: req.url,
pathVars: pathVars
}
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify(data))
}
},
{
pattern: '/api/test1/users/{userId}/{blogId}',
handle: (req, res, pathVars) => {
const data = {
url: req.url,
pathVars: pathVars
}
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify(data))
}
}
]
export default userMock