2017-04-10 01:46:18 +00:00
|
|
|
const express = require('express');
|
|
|
|
const bodyParser = require('body-parser');
|
2017-04-08 16:06:38 +00:00
|
|
|
|
2017-04-10 01:46:18 +00:00
|
|
|
const mustache = require('express');
|
|
|
|
|
|
|
|
var html = `
|
|
|
|
<!doctype html>
|
|
|
|
<html lang=en>
|
|
|
|
<head>
|
|
|
|
<link rel="stylesheet" href="https://unpkg.com/purecss@0.6.2/build/pure-min.css" integrity="sha384-UQiGfs9ICog+LwheBSRCt1o5cbyKIHbwjWscjemyBMT9YCUMZffs6UqUTd0hObXD" crossorigin="anonymous">
|
|
|
|
<style>
|
|
|
|
form { margin: 1em 0; }
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="pure-g" style="max-width: 768px; margin: 1em auto">
|
|
|
|
<div class="pure-u-1-1">
|
|
|
|
<h1>tag-reader-dummy</h1>
|
|
|
|
<form method="post" class="pure-form">
|
|
|
|
<input class="pure-button pure-button-primary" type="submit" name="uid" value="12121212">
|
|
|
|
</form>
|
|
|
|
<form method="post" class="pure-form">
|
|
|
|
<input class="pure-button pure-button-primary" type="submit" name="uid" value="BADC0FFEE">
|
|
|
|
</form>
|
|
|
|
<form method="post" class="pure-form">
|
|
|
|
<input type="text" name="uid" value="0123456789"> <input class="pure-button pure-button-primary" type="submit">
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
HTMLCollection.prototype.forEach = Array.prototype.forEach;
|
|
|
|
document.getElementsByTagName('form').forEach(function(form) {
|
|
|
|
form.onsubmit = function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var uid = e.target.querySelector('[name=uid]').value;
|
|
|
|
console.log(uid);
|
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('POST', 'http://localhost:8191/', true);
|
|
|
|
xhr.setRequestHeader('Content-Type', 'application\/x-www-form-urlencoded');
|
|
|
|
xhr.send('uid=' + uid);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`;
|
|
|
|
|
|
|
|
var app = express();
|
|
|
|
var server = require('http').createServer();
|
|
|
|
|
|
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
|
|
|
|
|
|
app.get('/', function(req, res, next) {
|
|
|
|
res.send(html);
|
|
|
|
});
|
|
|
|
|
|
|
|
app.post('/', function(req, res, next) {
|
|
|
|
var uid = req.body.uid;
|
|
|
|
if (uid) {
|
|
|
|
process.stdout.write(uid);
|
|
|
|
}
|
|
|
|
res.send('ok');
|
|
|
|
});
|
|
|
|
|
|
|
|
server.on('request', app);
|
|
|
|
|
|
|
|
server.listen(8191, function () {
|
|
|
|
process.stderr.write('tag-reader-dummy listening at http://localhost:8191');
|
|
|
|
})
|