Created
April 15, 2020 15:30
-
-
Save canfan/997b3e9d3c5c5def76b2e3ec1e73c6e3 to your computer and use it in GitHub Desktop.
simple HTTP post logger with UA based client identification
This file contains 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
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const cors = require('cors'); | |
const uas = { | |
index: [], | |
get(ua) { | |
let id = this.index.indexOf(ua); | |
if (id < 0) { | |
id = this.index.length; | |
this.index.push(ua); | |
console.log('-\nnew UA:', id, ua, '\n-'); | |
} | |
return id; | |
}, | |
}; | |
const app = express(); | |
app.use(cors()); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.use((req, res) => { | |
const ua = uas.get(req.get('User-Agent')); | |
console.log(ua, req.body); | |
res.end(); | |
}); | |
app.listen(8383); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment