1 Star 0 Fork 1

前端方圆/node_express_api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
api.js 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
fqcto 提交于 2019-07-16 17:16 . update
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)
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fqcto/node_express_api.git
git@gitee.com:fqcto/node_express_api.git
fqcto
node_express_api
node_express_api
master

搜索帮助