added WHOIS
This commit is contained in:
parent
3ca2226494
commit
1026f13843
|
@ -9,6 +9,7 @@ require('dotenv').config({ path: path.join(__dirname, '../.env') });
|
||||||
|
|
||||||
const status = require("./status/status");
|
const status = require("./status/status");
|
||||||
const exchangeRate = require("./exchange-rate/exchange-rate");
|
const exchangeRate = require("./exchange-rate/exchange-rate");
|
||||||
|
const whois = require("./whois/whois");
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.PORT || 2589;
|
const PORT = process.env.PORT || 2589;
|
||||||
|
@ -19,6 +20,7 @@ const cert = process.env.SSL_CERT_PATH || "/etc/letsencrypt/live/blahaj.tr/fullc
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use("/status", status);
|
app.use("/status", status);
|
||||||
app.use("/exchange-rate", exchangeRate);
|
app.use("/exchange-rate", exchangeRate);
|
||||||
|
app.use("/whois", whois);
|
||||||
|
|
||||||
// try to load certificates
|
// try to load certificates
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -30,7 +30,7 @@ async function checkServers() {
|
||||||
for (const server of REMOTE_SERVERS) {
|
for (const server of REMOTE_SERVERS) {
|
||||||
try {
|
try {
|
||||||
const res = await ping.promise.probe(server.host, {
|
const res = await ping.promise.probe(server.host, {
|
||||||
timeout: 2, // Set a timeout of 2 seconds
|
timeout: 4, // Set a timeout of 4 seconds
|
||||||
});
|
});
|
||||||
serversStatus[server.name].online = res.alive;
|
serversStatus[server.name].online = res.alive;
|
||||||
serversStatus[server.name].responseTime = res.time;
|
serversStatus[server.name].responseTime = res.time;
|
||||||
|
|
69
api/whois/whois.js
Normal file
69
api/whois/whois.js
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
const express = require('express');
|
||||||
|
const whois = require('whois-json');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
// GET endpoint for WHOIS lookup
|
||||||
|
router.get('/:domain', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const domain = req.params.domain;
|
||||||
|
|
||||||
|
if (!domain) {
|
||||||
|
return res.status(400).json({ error: 'Domain parameter is required' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await whois(domain);
|
||||||
|
|
||||||
|
// Format the response in a clean structure
|
||||||
|
const whoisData = {
|
||||||
|
domain: domain,
|
||||||
|
registrar: result.registrar || "Not available",
|
||||||
|
creationDate: result.creationDate ? new Date(result.creationDate).toISOString() : "Not available",
|
||||||
|
expirationDate: result.expirationDate ? new Date(result.expirationDate).toISOString() : "Not available",
|
||||||
|
nameServers: Array.isArray(result.nameServers) ? result.nameServers : (result.nameServers ? [result.nameServers] : ["Not available"]),
|
||||||
|
status: Array.isArray(result.status) ? result.status : (result.status ? [result.status] : ["Not available"]),
|
||||||
|
raw: result // Include the full raw data for advanced usage
|
||||||
|
};
|
||||||
|
|
||||||
|
res.json(whoisData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('WHOIS API Error:', error);
|
||||||
|
res.status(500).json({
|
||||||
|
error: 'Failed to fetch WHOIS information',
|
||||||
|
message: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// POST endpoint for WHOIS lookup (alternative to GET with request body)
|
||||||
|
router.post('/', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const domain = req.body.domain;
|
||||||
|
|
||||||
|
if (!domain) {
|
||||||
|
return res.status(400).json({ error: 'Domain parameter is required in request body' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await whois(domain);
|
||||||
|
|
||||||
|
// Format the response in a clean structure
|
||||||
|
const whoisData = {
|
||||||
|
domain: domain,
|
||||||
|
registrar: result.registrar || "Not available",
|
||||||
|
creationDate: result.creationDate ? new Date(result.creationDate).toISOString() : "Not available",
|
||||||
|
expirationDate: result.expirationDate ? new Date(result.expirationDate).toISOString() : "Not available",
|
||||||
|
nameServers: Array.isArray(result.nameServers) ? result.nameServers : (result.nameServers ? [result.nameServers] : ["Not available"]),
|
||||||
|
status: Array.isArray(result.status) ? result.status : (result.status ? [result.status] : ["Not available"]),
|
||||||
|
raw: result // Include the full raw data for advanced usage
|
||||||
|
};
|
||||||
|
|
||||||
|
res.json(whoisData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('WHOIS API Error:', error);
|
||||||
|
res.status(500).json({
|
||||||
|
error: 'Failed to fetch WHOIS information',
|
||||||
|
message: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
Loading…
Reference in a new issue