nc-helper / index.js
chb2025's picture
Update index.js
821b7f4 verified
const express = require('express');
const app = express();
const port = process.env.PORT || 7860;
const requestIp = require('request-ip');
app.use(express.static('public'));
// Create a route that returns the HTML with Beijing time and IP
app.get('/', (req, res) => {
const clientIp = requestIp.getClientIp(req) || "Unknown";
// Get current time in Beijing (UTC+8)
const now = new Date();
const beijingTime = new Date(now.getTime() + (8 * 60 * 60 * 1000));
const hours = beijingTime.getUTCHours().toString().padStart(2, '0');
const minutes = beijingTime.getUTCMinutes().toString().padStart(2, '0');
const timeString = `${hours}:${minutes}`;
const html = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
font-family: Arial, sans-serif;
}
.container {
display: flex;
align-items: center;
padding: 6px 10px;
background: linear-gradient(135deg, #ff0844 0%, #8000ff 50%, #0061ff 100%);
border-radius: 6px;
color: white;
height: 100%;
box-sizing: border-box;
}
.clock-emoji {
margin-right: 6px;
font-size: 14px;
}
.info-text {
font-size: 13px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<div class="container">
<span class="clock-emoji">πŸ•’</span>
<span class="info-text">${timeString} | IP ${clientIp}</span>
</div>
<script>
// Reload the page every minute to update time
setTimeout(() => {
window.location.reload();
}, 60000);
</script>
</body>
</html>
`;
res.send(html);
});
app.listen(port, '0.0.0.0', () => {
console.log(`Server running on port ${port}`);
});