-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlight-scheduler-settings.js
32 lines (30 loc) · 1006 Bytes
/
light-scheduler-settings.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
const axios = require('axios')
var pjson = require('./package.json')
module.exports = function (RED) {
function LightSchedulerSettings(n) {
RED.nodes.createNode(this, n)
this.name = n.name
this.latitude = n.latitude
this.longitude = n.longitude
}
RED.nodes.registerType('light-scheduler-settings', LightSchedulerSettings)
// Get latitude/longitude using geoip lookup.
RED.httpAdmin.get('/light-scheduler/geoinfo.json', async function (req, res) {
try {
const response = await axios.get(
'https://2quhxokvva.execute-api.eu-west-1.amazonaws.com/default/light-scheduler-geoip?v=' + pjson.version
)
if (response.status != 200) {
res.status(500)
res.json(null)
}
let data = response.data
res.status(200)
res.json({city: data.city, country: data.country_name, latitude: data.latitude, longitude: data.longitude})
} catch (err) {
console.error(err)
res.status(500)
res.json(null)
}
})
}