-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
33 lines (28 loc) · 876 Bytes
/
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
var http = require('http');
var twit = require('twitter');
var fs = require("fs");
var index = fs.readFileSync("./index.html").toString();
var url = require('url');
var keys= require('./keys.js')
var twitter = new twit(keys.secretkeys);
http.createServer(function (req, res) {
if(req.url === '/'){
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(index);
} else {
var url_parts = url.parse(req.url, true);
console.log(url_parts)
var geocode = url_parts.query["geocode"];
} if (geocode) {
twitter.get('search/tweets', {count:10, geocode: geocode},
function(error,tweets,response){
res.writeHead(200, {'Content-Type': 'application/javascript'});
res.end(JSON.stringify(tweets.statuses));
});
}
else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(index);
}
}
).listen(process.env.PORT || 3000);