-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathserver.js
37 lines (30 loc) · 927 Bytes
/
server.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
var express = require('express');
var axios = require('axios');
var app = express();
app.use('/public', express.static('public'));
app.get('/', function (req, res) {
res.sendFile(__dirname + "/" + "index.html");
})
app.get('/req_json_api', async function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'});
requrl = req.url.slice(18);
console.log('requrl=%s',requrl);
let jsondata = await axios({
methods: 'get',
url: requrl
})
.then(function (response) {
return response.data;
})
.catch(function (error) {
if(error.response){
console.log("sth.error!status=%s,statusText=%s",error.response.status,error.response.statusText);
}
});
res.end(JSON.stringify(jsondata));
})
var server = app.listen(2021, function () {
var host = server.address().address
var port = server.address().port
console.log("应用实例,访问地址为 http://%s:%s", host, port)
})