Better error handling
This commit is contained in:
parent
6960da6b45
commit
8064752200
12
app.js
12
app.js
@ -3,13 +3,19 @@ const { Resolver } = require('dns').promises
|
|||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
const r = new Resolver()
|
const r = new Resolver()
|
||||||
|
r.setServers(['1.1.1.1'])
|
||||||
|
|
||||||
app.get('/', async (req, res) => {
|
app.get('/', async (req, res) => {
|
||||||
res.header('Content-type: text/plain')
|
res.header('Content-type: text/plain')
|
||||||
const ip = req.connection.remoteAddress
|
let ip, host
|
||||||
let host
|
|
||||||
try {
|
try {
|
||||||
host = await r.reverse(/.*:([^:]+)$/.exec(ip)[1])
|
ip = /.*:([^:]+)$/.exec(req.connection.remoteAddress)[1]
|
||||||
|
} catch(err) {
|
||||||
|
console.log(err.message)
|
||||||
|
ip = 'ERR'
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
host = await r.reverse(ip)
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log(err.message)
|
console.log(err.message)
|
||||||
host = 'ERR'
|
host = 'ERR'
|
||||||
|
Loading…
Reference in New Issue
Block a user