-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
51 lines (35 loc) · 1.09 KB
/
app.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
const port = process.env.PORT || 3002;
const env = process.env.NODE_ENV || "development";
const http = require('http');
const Pokeio = require('pokemon-go-node-api');
const config = require('./config.json');
const location = {
type: "name",
name: "Strasbourg France"
};
Pokeio.init(config.username, config.password, location, config.provider, (err) => {
if(err){
console.error(err);
}
});
const utils = require("./utils");
let scanner = require('./scanner');
var app = http.createServer(function(req, res) {
if(req.url.match(/scan.json/g)){
params = utils.format_params(req);
console.log(params);
res.writeHead(200, {'Content-Type': 'application/json'});
const response = scanner.scan_nearby(params.lat, params.lon);
scanner.scan_nearby().then( (response) => {
res.end(JSON.stringify(response));
}, (err) =>{
res.end(JSON.stringify(err));
}
);
}else{
res.writeHead(200, {'Content-Type': 'application/json'});
res.end("{}");
}
});
console.log("---------- server running on port "+port+" -----------------")
app.listen(port);