Created
March 14, 2014 00:47
-
-
Save undoZen/9540170 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
var express = require('express'); | |
var hasBody = require('express/node_modules/connect').utils.hasBody; | |
var getBody = require('express/node_modules/connect/node_modules/raw-body'); | |
var app = express(); | |
app.use(express.static(__dirname)); | |
app.post('/enter', express.urlencoded(), function (req, res, next) { | |
if (req.body.wifi) console.log('"' + (new Date).toGMTString() + '","enter","'+req.body.wifi+'"'); | |
next(); | |
}); | |
app.post('/leave', express.urlencoded(), function (req, res, next) { | |
if (req.body.wifi) console.log('"' + (new Date).toGMTString() + '","leave","'+req.body.wifi+'"'); | |
next(); | |
}); | |
app.post('/wifi', function (req, res, next) { | |
if (!hasBody(req)) return next(); | |
if (!req.headers['user-agent'].match(/^tasker/i)) return next(); | |
getBody(req, { | |
limit: '1mb', | |
length: req.headers['content-length'], | |
encoding: 'utf8' | |
}, function (err, buf) { | |
if (err) return next(err); | |
console.log('"' + (new Date).toGMTString() + '","enter",' + buf.split('\n')[2]); | |
next(); | |
}) | |
}); | |
app.use(function (req, res) { | |
res.statusCode = 204; | |
res.end(); | |
}); | |
app.listen(8989); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment