Skip to content

Instantly share code, notes, and snippets.

@michielbdejong
Last active February 2, 2016 11:47
Show Gist options
  • Save michielbdejong/a3f2fb3a022d01426e0f to your computer and use it in GitHub Desktop.
Save michielbdejong/a3f2fb3a022d01426e0f to your computer and use it in GitHub Desktop.
var http = require('http');
var qr = require('qr-image');
var drRandom = require('drossel-random');
var ipaddress = '10.246.34.43';
var ports = {
qr: 12345,
api: 12346
};
var appOrigin = 'https://local-secure.5apps.com';
var appUrl = appOrigin + '/';
var apiUrl = 'http://' + ipaddress + ':' + ports.api;
// serve QR code on a screen on the local device:
http.createServer((req, res) => {
res.writeHead(200);
res.write('<html><body style="width: 400px; height: 400px">');
res.write(qr.imageSync(appUrl + '#' + drRandom(40) + apiUrl, { type: 'svg' }));
res.end('</body></html>');
}).listen(ports.qr);
// serve an API on the local network:
http.createServer((req, res) => {
var body = '';
req.on('data', function(chunk) {
body += chunk;
});
req.on('end', function() {
res.writeHead(200, {
'Access-Control-Allow-Origin': appOrigin,
'Access-Control-Allow-Methods': 'POST'
});
res.end('You sent:' + body);
});
}).listen(ports.api);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment