Created
February 25, 2018 02:11
-
-
Save alana314/5966e9f56207c435c088ea70dfde00a6 to your computer and use it in GitHub Desktop.
Node Proxy to forward commands to Yun
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
//replace {myport} with any port number and {mytoken} with any URL-friendly string. | |
var request = require('request'); | |
const express = require('express') | |
const app = express() | |
app.get('/', (req, res) => { | |
if(req.query.token != '{mytoken}') | |
{ | |
res.send('Invalid Token'); | |
return; | |
} | |
//bridge wants /arduino/command/ int/int for some reason | |
res.send('ok'); //respond first, otherwise it might time out | |
request('http://robotarmarduino.local/arduino/' + req.query.command + '/1/1', function (error, response, html) { | |
if (!error && response.statusCode == 200) { | |
//res.send('ok'); | |
console.log('command sent: ' + req.query.command); | |
console.log('response:' + html); | |
}else | |
{ | |
//res.send('error'); | |
console.log('error: ', error, response, html); | |
} | |
}); | |
} | |
) | |
app.listen({myport}, () => console.log('Proxy listening on port {myport}')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment