This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (45 loc) · 1.48 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//git
//const updater = require('./db-downloader.js')
const express = require('express');
const app = express();
/*
const WebServiceClient = require('@maxmind/geoip2-node').WebServiceClient;
const client = new WebServiceClient('530667', 'eUvNCKA9SwdtNdQj');
client.insights('2400:8901::f03c:92ff:fe9b:edd5').then(response => {
console.log(response);
console.log(response.country.isoCode); // 'CA'
console.log(response.postal.code); // 'M5S'
console.log(response.traits.userType); // 'school'
}).catch(err => {
console.log(err);
});
*/
const r = require('./modules/geodb');
console.log(r('2400:8901::f03c:92ff:fe9b:edd5'))
console.log(r('2400:8901::f03c:92ff:fe9b:edd5'))
app.get('/', (req, res) => {
//console.log(req);
res.send('<h1>Hello Express app!</h1>\n This product includes GeoLite2 data created by MaxMind, available from <a href="https://www.maxmind.com">https://www.maxmind.com</a>.')
});
app.get('/query/:ip', (req, res) => {
//console.log(req);
let ip = req.params.ip;
console.log(req.params.ip);
res.send(r(ip));
});
app.get('/dbfile/:type', (req, res) => {
let type = req.params.type;
if (type !== 'asn' && type !== 'city') {
res.send('Invalid request');
} else {
require('./db-downloader.js').maxmind(type).finally(
() => {
let tarFilename = type === 'asn' ? './data/GeoLite2-ASN.mmdb' : './data/GeoLite2-City.mmdb';
res.download(tarFilename);
}
);
}
});
app.listen(3000, () => {
console.log('server started');
});