feat: add files

This commit is contained in:
obvTiger 2025-04-09 10:09:13 +02:00
parent b44931ff90
commit d5baecaaca
3 changed files with 137 additions and 3 deletions

81
server.js Normal file
View file

@ -0,0 +1,81 @@
const http = require('http');
function parseArgs() {
const args = process.argv.slice(2);
const options = {
port: 3000,
host: 'localhost'
};
for (let i = 0; i < args.length; i++) {
if (args[i] === '--port' || args[i] === '-p') {
options.port = parseInt(args[i + 1]) || 3000;
i++;
} else if (args[i] === '--host' || args[i] === '-h') {
options.host = args[i + 1] || 'localhost';
i++;
} else if (args[i] === '--help') {
console.log(`
Usage: node server.js [options]
Options:
--port, -p Port to run the server on (default: 3000)
--host, -h Host to bind the server to (default: localhost)
--help Show this help message
`);
process.exit(0);
}
}
return options;
}
const options = parseArgs();
const server = http.createServer((req, res) => {
let body = '';
console.log(`\n${new Date().toISOString()} - ${req.method} ${req.url}`);
console.log('Headers:', JSON.stringify(req.headers, null, 2));
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', () => {
if (body) {
try {
const jsonBody = JSON.parse(body);
console.log('Body:', JSON.stringify(jsonBody, null, 2));
} catch {
console.log('Body:', body);
}
}
res.writeHead(200, {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS'
});
const response = {
message: 'Request received',
method: req.method,
url: req.url,
timestamp: new Date().toISOString()
};
res.end(JSON.stringify(response));
});
});
server.listen(options.port, options.host, () => {
console.log(`Webhook listener running on http://${options.host}:${options.port}`);
process.on('SIGINT', () => {
console.log('\nReceived CTRL+C - Shutting down server...');
server.close(() => {
console.log('Server closed');
process.exit(0);
});
});
});