let http = require('http');
let fs = require('fs');
let url = require('url');
http.createServer(function (req, res){
(请求头信息)
res.setHeader("Access-Control-Allow-Origin", "*"); res.setHeader("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With"); res.setHeader("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); res.setHeader("X-Powered-By", ' 3.2.1')
//获取热门图书
if(pathname==='/hot'){
fs.readFile('./book.json','utf8',function (err,data) {
res.setHeader('content-type','application/json;charset=utf-8');
data = JSON.parse(data).reverse().slice(0,6)
return res.end(JSON.stringify(data));
});
}
(对应的API)
export let getHot = () => { return axios.get("/hot")}
网友评论