Created
June 20, 2017 08:41
-
-
Save jffz/19cea41da58f2f6796804e284c87230d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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