代码拉取完成,页面将自动刷新
var express = require('express');
var app = express();
app.all('*',function(req,res,next){ //
res.header("Access-Control-Allow-Origin","*");
res.header("Access-Control-Allow-Headers","X-Request-With");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",'3.2.1');
res.header("Content-Type","application/json;charset=utf-8");
next();
});
var infor = [ //传前端的数据
{
name:'ZZSB',
age:20,
sex:'男',
hobby:'Adidas'
},
{
name:'ZZSB',
age:21,
sex:'男',
hobby:'Nick'
},
{
name:'ZZSB',
age:22,
sex:'男',
hobby:'绿水鬼'
},
{
name:'ZZSB',
age:23,
sex:'男',
hobby:'奔驰S'
},
{
name:'ZZSB',
age:24,
sex:'男',
hobby:'美女豪车'
},
]
app.get('/api',function(req,res){ //配置接口api
res.status(200),
res.json(infor)
})
// 配置服务端口
var server = app.listen(3002,function(){
var host = server.address().address;
var port = server.address().port;
console.log('listen at http://%s:%s',host,port)
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。