123456789101112131415161718192021222324252627282930313233343536 |
- const express = require('express');
- const bodyParser = require('body-parser');
- const app = express();
- const PORT = 3000;
- app.use(bodyParser.json());
- const users = {
- 'admin': 'password123'
- };
- app.post('/api/login', (req, res) => {
- const { username, password } = req.body;
-
- if (users[username] && users[username] === password) {
-
- res.status(200).send({ message: '登录成功' });
- } else {
-
- res.status(401).send({ message: '用户名或密码错误' });
- }
- });
- app.listen(PORT, () => {
- console.log(`服务器运行在 http://localhost:${PORT}`);
- });
|