-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_bkp.js
79 lines (61 loc) · 1.94 KB
/
index_bkp.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var express = require('express');
var app = express();
var url = require('url');
var request = require('request');
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.set('port', (process.env.PORT || 9001));
app.get('/', function(req, res){
res.send('Wiki News works fine!!');
});
/*app.post('/post', function(req, res){
var parsed_url = url.format({
pathname: 'http://wiki.news.com.au/rest/prototype/1/search/name.json',
query: {
query: req.body.text // search query
}
});
console.log(parsed_url);
request(parsed_url, {timeout: 1500}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body);
//var obj = data.group;
//var first_item = obj[Object.keys(obj)[0]];
// var first_snippet = first_page.extract.substring(0,250)+'...';
// var first_title = first_item.result[0].title;
// var first_creator = (first_item.result[0].creator ? first_item.result[0].creator.displayName : "Anonymous")
var first_title = "Title here";
var first_creator = "Creator name";
// var result_url = 'http://en.wikipedia.org/wiki/' + first_page.title;
var body = {
response_type: "in_channel",
text: "Found something on the wiki...",
attachments: [
{
title: first_title,
title_link: 'http://google.com',
text: first_creator
}
]
};
res.send(body);
}
});
});*/
request({
url: 'http://wiki.news.com.au/rest/prototype/1/search?query=jpml',
method: 'POST',
proxy: 'http://pac.news.net.au/proxy.pac',
body: 'Hello'
}, function(error, res, body){
if(error) {
console.log(error);
} else {
console.log(res.statusCode, body);
}
// res.end();
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});