-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpd.js
38 lines (32 loc) · 871 Bytes
/
httpd.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
var express = require('express');
var bodyParser = require('body-parser');
var axios = require('axios');
const port = 19987
const prefix = '/doudou'
var app = express();
app.use(prefix, express.static('./dist')) /* for /foo (after rewriting) */
app.use(bodyParser.json())
console.log('Listening on port ' + port)
app.listen(port)
app.get(prefix + '/query', function (req, ret) {
const query = req.query.q
const page = req.query.p
console.log(`searching "${query}" @ page ${page}`)
axios.post('http://127.0.0.1:19986', {
'q': query, 'p': parseInt(page)
}).then(function (res) {
ret.json(res.data)
}).catch(function (err) {
console.log('error', err.code)
ret.json({
"cur_page": 1,
"tot_page": -1,
"list": []
})
})
})
process.on('SIGINT', function() {
console.log('')
console.log('Bye bye.')
process.exit()
})