Created
January 10, 2017 20:44
-
-
Save hdurdle/7359531d7ddc6b32e8f767a2a3e4ae1d to your computer and use it in GitHub Desktop.
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
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var fs = require('fs'); | |
var request = require('request'); | |
var app = express(); | |
app.use(bodyParser.json()); | |
app.get('/', function(req, res) { | |
console.log('GET /') | |
var html = '<html><body>POST please</body>'; | |
res.writeHead(200, { | |
'Content-Type': 'text/html' | |
}); | |
res.end(html); | |
}); | |
app.post('/motion/', function(req, res) { | |
console.log('POST /'); | |
console.dir(req.body); | |
res.writeHead(200, { | |
'Content-Type': 'text/html' | |
}); | |
// send the internal post | |
request({ | |
url: 'http://plexclient:3005/jsonrpc', | |
method: 'POST', | |
json: req.body | |
}, function(error, response, body) { | |
if (error) { | |
console.log(error); | |
} else { | |
console.log(response.statusCode, body); | |
} | |
}); | |
res.end('OK'); | |
}); | |
port = 6678; | |
app.listen(port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment