-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
52 lines (40 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var server = require("./server");
var router = require("./router");
var requestHandlers = require("./requestHandlers");
var handle = {};
handle["/"] = requestHandlers.start;
handle["/start"] = requestHandlers.start;
handle["/upload"] = requestHandlers.upload;
handle["/api"] = requestHandlers.api;
handle["/env"] = requestHandlers.env;
server.start(router.route, handle);
// 接口
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-Requested-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 questions=[
{
"user_info":"wangch"
},
{
"user_info":"wangd"
}];
//写个接口123
app.get('/userInfo',function(req,res){
res.status(200),
res.json(questions)
});
//配置服务端口
var openServer = app.listen(3000, function () {
var host = openServer.address().address;
var port = openServer.address().port;
console.log('Example app listening at http://%s:%s', host, port);
})