1 Star 0 Fork 0

Marvin/http-tempplate-express

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
Marvin 提交于 2021-05-08 01:25 . ss
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}})
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/canyuegongzi/http-tempplate-express.git
[email protected]:canyuegongzi/http-tempplate-express.git
canyuegongzi
http-tempplate-express
http-tempplate-express
master

搜索帮助