-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (31 loc) · 1.14 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
const express = require('express');
const app = express();
const port = 3000;
app.get('/track', (req, res) => {
// Get the real IP address from X-Forwarded-For header or use req.ip
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
const timestamp = new Date().toISOString();
// Log the tracking details
console.log(`${timestamp} - IP: ${ip}`);
// Send a 1x1 transparent PNG as a response
const pixel = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wcAAgcB4kfECXcAAAAASUVORK5CYII=',
'base64'
);
res.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': pixel.length,
});
res.end(pixel);
});
app.get('/redirect', (req, res) => {
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
const timestamp = new Date().toISOString();
// Log the tracking details
console.log(`${timestamp} - IP: ${ip}`);
// Redirect the user
res.redirect('https://www.kleinanzeigen.de/stadt/regensburg/');
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});