24 lines
936 B
JavaScript
24 lines
936 B
JavaScript
|
|
/**
|
||
|
|
* Simple mock server for login credential handling.
|
||
|
|
* Run with: node mock-server.js
|
||
|
|
* It listens on port 4000 and exposes:
|
||
|
|
* POST /api/login (expects { username, password } ), returns token on success
|
||
|
|
* GET /api/menus and GET /api/user are served from /public/api by vite dev server in normal flow.
|
||
|
|
*/
|
||
|
|
import express from 'express'
|
||
|
|
import bodyParser from 'body-parser'
|
||
|
|
const app = express()
|
||
|
|
app.use(bodyParser.json())
|
||
|
|
|
||
|
|
app.post('/api/login', (req,res) => {
|
||
|
|
const { username, password } = req.body || {}
|
||
|
|
// simple check: admin / 123456 succeed, or if username === 'scan' allow (for QR)
|
||
|
|
if ((username === 'admin' && password === '123456') || username === 'scan') {
|
||
|
|
return res.json({ code: 200, token: 'mocked-jwt-token' })
|
||
|
|
}
|
||
|
|
return res.status(401).json({ code: 401, message: '账号或密码错误' })
|
||
|
|
})
|
||
|
|
|
||
|
|
const port = 4000
|
||
|
|
app.listen(port, () => console.log(`Mock server running on http://localhost:${port}`))
|