//"30_Axios"是搭建服务器,下一节课的"31_axios客户端"是使用服务器 const express = require('express') //允许跨域 const cors = require('cors'); //body-parser中间件:解析post请求的JSON数据 const bodyParser = require('body-parser') const app = express(); app.use(cors()); //处理参数 app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); // ?形式传递参数 app.get('/axios',(req,res)=>{ res.send('gei请求传递参数1:' + req.query.id) }) //restful形式传递参数 app.get('/axios/:id',(req,res)=>{ res.send('gei请求传递参数2:' + req.params.id) }) //Params形式传递参数 app.get('/axios',(req,res)=>{ res.send('get请求传递参数3:' + req.body.uname+'----'+req.body.pwd) }) //post请求 app.post('/axios',(req,res)=>{ res.send('axios的post请求:' + req.body.uname+'----'+req.body.pwd) }) //post请求 app.put('/axios',(req,res)=>{ res.send('axios的put请求:' + req.body.uname+'----'+req.body.pwd) }) app.listen(3001,()=>{ console.log('服务器启动成功啦'); })