Skip to content

Instantly share code, notes, and snippets.

@phuedx
Created February 12, 2019 17:06
Show Gist options
  • Save phuedx/c0f045078f293f9d8a4e19a2ab87a494 to your computer and use it in GitHub Desktop.
Save phuedx/c0f045078f293f9d8a4e19a2ab87a494 to your computer and use it in GitHub Desktop.
Toy MediaWiki EventLogging catter
const PORT = 8035;
const http = require('http');
const url = require('url');
const server = http.createServer((req, res) => {
const i = req.url.indexOf('?');
let rawEvent = req.url;
// The EventLogging client doesn't specify a name for the query parameter
// and doesn't pass any other query parameters.
rawEvent = rawEvent.substring(i + 1);
// The EventLogging client appends a ";" to the URI-encoded event.
rawEvent = rawEvent.slice(0, -1);
const event = JSON.parse(decodeURIComponent(rawEvent));
console.log(+new Date());
console.log(JSON.stringify(event, null, 2));
console.log();
res.writeHead(204, 'No Content');
res.end();
})
server.listen(PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment