代码拉取完成,页面将自动刷新
const express = require('express')
const bodyParser = require('body-parser');
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
// 创建 application/x-www-form-urlencoded 编码解析(post方法)
const urlencodedParser = bodyParser.urlencoded({ extended: false })
//设置跨域访问
app.all('*', function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
res.header("Content-Type", "application/json;charset=utf-8");
next();
})
//登录
app.post('/login', bodyParser.json(), function (req, res) {
console.log('参数');
console.log(req.body);
console.log(req.body.username);
const username = req.body.username;
const password = req.body.password;
res.status(200)
res.json({message: "success", data: {username, password}})
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。