-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathutils.js
30 lines (26 loc) · 801 Bytes
/
utils.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
const moment = require('moment')
const maxmind = require('maxmind')
const conf = require('nconf')
const path = require('path')
conf.file({file: path.join(__dirname, 'cfg.json')})
conf.defaults({
port: 3013,
bind: '127.0.0.1',
servers: [{
name: 'Server', host: '127.0.0.1', man_port: 7656
}],
username: 'admin',
password: 'admin',
web: {
dateFormat: 'HH:mm:ss - DD.MM.YY'
}
})
const log = (...args) => console.log(...[moment().format(conf.get('web').dateFormat), ...args])
const loadIPdatabase = () => {
return new Promise((resolve, reject) => {
maxmind.open(path.join(__dirname, 'GeoLite2-City.mmdb'))
.then((lookup) => resolve(ip => (ip ? lookup.get(ip) : false)))
.catch((err) => {reject();log(err)})
})
}
module.exports = {log, loadIPdatabase, conf}