Skip to content

Instantly share code, notes, and snippets.

@jffz
Created June 20, 2017 08:41
Show Gist options
  • Save jffz/19cea41da58f2f6796804e284c87230d to your computer and use it in GitHub Desktop.
Save jffz/19cea41da58f2f6796804e284c87230d to your computer and use it in GitHub Desktop.
'use strict'
const express = require('express')
const bodyParser = require('body-parser')
const SrcdsLogParser = require('better-srcds-log-parser').SrcdsLogParser
// Create a new instance of express
const app = express()
const parser = SrcdsLogParser()
// Tell express to use the body-parser middleware and to not parse extended bodies
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json());
app.use (function(req, res, next) {
var logs='';
req.setEncoding('utf8');
req.on('data', function(chunk) {
logs += chunk;
});
req.on('end', function() {
req.bodyRaw = logs;
req.bodyParsed = logs.trim().split(/\n/);
req.bodyParsed.forEach(function(log) {
console.log(parser.parseline(log));
next();
});
});
// Route that receives a POST request to /sms
app.post('/', function (req, res) {
//console.log(req.bodyParsed);
console.log(log.date);
  res.sendStatus(200);
})
// Tell our app to listen on port 3000
app.listen(3000, function (err) {
  if (err) {
    throw err
  }
  console.log('Server started on port 3000')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment