//test.js
const http=require("http")
const url=require("url")
// 创建服务器
const server=http.createServer((req,res)=>{
const {pathname}=url.parse(req.url)
const options={
host:'localhost',
port:'8080',
path:pathname,
headers:{token:"xxx"}
}
const callback=(response)=>{
const {statusCode,headers}=response
res.writeHead(statusCode,{...headers})
response.pipe(res)
}
http.request(options,callback).end()
}).listen("3030")
//server.js
const http=require("http")
const server=http.createServer((req,res)=>{
const {headers={}}=req
res.writeHead(200,{'Content-Type':'application/json;charset=utf-8'})
if (headers.token) {
res.end(JSON.stringify({code:0,message:'success',data:[]}))
} else {
res.end(JSON.stringify({code:-1,message:'您还没有开通权限'}))
}
})
server.listen("8080",()=>{
console.log("端口正在运行");
})
