-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
78 lines (60 loc) · 1.74 KB
/
server.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require('dotenv').config();
const express = require('express');
const axios = require('axios');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.static(path.join(__dirname, 'public')));
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.get('/', (req, res) => {
res.render('index', { result: null });
});
app.get('/whois', async (req, res) => {
const domain = req.query.domain;
if (!domain) {
return res.status(400).json({ error: 'Please provide a domain name' });
}
try {
const response = await axios({
method: 'GET',
url: `https://whois40.p.rapidapi.com/whois?q=${domain}`,
headers: {
'X-RapidAPI-Key': process.env.WHOIS_API_KEY,
'X-RapidAPI-Host': 'whois40.p.rapidapi.com',
},
});
res.json(response.data);
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Error fetching WHOIS data' });
}
});
// Handle the Hosting lookup
app.get('/lookup', async (req, res) => {
const domain = req.query.domain;
if (!domain) {
return res.render('index', { result: 'Please provide a domain name' });
}
try {
const response = await axios({
method: 'GET',
url: `https://ipwhois.app/json/${domain}`,
});
const whoisData = response.data;
res.render('index', { result: whoisData });
} catch (error) {
console.error(error);
res.render('index', { result: 'Error fetching data' });
}
});
app.get('/contact', (req, res) => {
res.render('contact');
});
app.use((req, res) => {
const ip = req.ip;
res.status(404).render('404', { ip: ip });
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});