Skip to content

Instantly share code, notes, and snippets.

@hdurdle
Created January 10, 2017 20:44
Show Gist options
  • Save hdurdle/7359531d7ddc6b32e8f767a2a3e4ae1d to your computer and use it in GitHub Desktop.
Save hdurdle/7359531d7ddc6b32e8f767a2a3e4ae1d to your computer and use it in GitHub Desktop.
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