Skip to content

Mock Server

Nitro-based mock backend providing API simulation for H5 apps during development.

Start

The mock server auto-starts at http://localhost:5320 via the nitro-mock Vite plugin.

Manual start:

bash
cd apps/backend-mock
pnpm start

API Endpoints

Authentication

MethodPathDescription
POST/api/auth/loginLogin, returns accessToken
POST/api/auth/logoutLogout, clears refreshToken
POST/api/auth/refreshRefresh accessToken

User

MethodPathDescription
GET/api/user/infoGet user info (requires Bearer Token)

Products

MethodPathDescription
GET/api/product/listProduct list (supports ?page=1&pageSize=10)
GET/api/product/detailProduct detail (?id=1)

Upload

MethodPathDescription
POST/api/uploadFile upload (returns mock URL)

Test Accounts

UsernamePasswordRole
user123456Regular user
admin123456Admin

Login Request Example

bash
curl -X POST http://localhost:5320/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"user","password":"123456"}'

Response:

json
{
  "code": 0,
  "data": {
    "id": 0,
    "realName": "Test User",
    "avatar": "...",
    "roles": ["user"],
    "username": "user",
    "accessToken": "eyJhbGciOiJIUzI1NiI..."
  },
  "message": "ok"
}

JWT Authentication

  • Access Token validity: 7 days
  • Refresh Token validity: 30 days (stored in HttpOnly Cookie)

Released under the MIT License.