目录
初版1
// 搭建一个简易服务器
// 1引入http
let http=require('http')
// 2创建服务器
let app=http.createServer((req,res)=>{
// 2-1假设请求地址与接口地址相同
if(req.url=="/api" ){
// 2-1.1成功返回ok
res.end('ok')
}else{
// 2-1.2失败返回other
res.end ("other")
}
})
// 3对服务器的监听
// (在cmd上 运行 node proxy.js(本页面标题);服务器启动成功;在浏览器上监听,进入localhost:8888)
app.listen(8888,()=>{
console.log('服务器启动');
})
初版2
1 index.html
// 1jsonp跨域
let Btn = document.querySelector('button')