ip-echo/main.js

17 lines
397 B
JavaScript
Raw Normal View History

2019-10-06 08:18:49 +02:00
const geoip = require('geoip-lite')
const express = require('express')
const cors = require('cors')
const app = express()
const port = 3000
2019-10-06 08:34:03 +02:00
app.use(cors())
2019-10-06 08:18:49 +02:00
app.get('/', (req, res) => {
const ip = req.headers['x-real-ip'] || req.connection.remoteAddress
const geo = geoip.lookup(ip) || {}
geo.ip = ip
res.send(geo)
})
app.listen(port, () => console.log(`App is listening on port ${port}!`))