Fix logging more?

This commit is contained in:
Christopher Cookman 2025-08-21 07:52:57 -06:00
parent 4e6dbcea8c
commit ef62c56020

View file

@ -3,20 +3,27 @@ const express = require('express');
const app = express();
const port = process.env.SERVER_PORT || 3000;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use((req, res, next) => {
//Logger
// [timestamp] method - url; UA; IP; roblox-id header if it exists
const timestamp = new Date().toISOString();
const method = req.method;
const url = req.originalUrl;
const userAgent = req.headers['user-agent'] || 'unknown';
const ip = req.headers['x-forwarded-for'] || req.remoteAddress || 'unknown';
const robloxId = req.headers['roblox-id'] || 'none';
console.log(`[${timestamp}] ${method} - ${url}; UA: ${userAgent}; IP: ${ip}; Roblox-ID: ${robloxId}`);
next();
});
app.get('/', (req, res) => {
res.send('Hello, world!');
});
app.get('/time.php', (req, res) => {
// Logging
if (req.headers['user-agent'] && req.headers['user-agent'].includes('Roblox/Linux')) { // Is roblox server
console.log(`Request from Roblox server. Place ${req.headers['roblox-id']} (${req.headers['x-forwarded-for'] || 'unknown IP'})`);
} else if(req.headers['user-agent'] && req.headers['user-agent'].includes('RobloxStudio')) { // Is roblox studio
console.log(`Request from Roblox Studio. Place ${req.headers['roblox-id']} (${req.headers['x-forwarded-for'] || 'unknown IP'})`);
} else {
console.log(`Request from ${req.headers['user-agent'] || `unknown user agent ${req.headers['x-forwarded-for'] || 'unknown IP'}`}`);
}
// This endpoint returns the current time in a specific format based on the timezone provided
const tz = req.query.zone || 'UTC';
const date = new Date();
try {