Skip to content

Instantly share code, notes, and snippets.

@phdd
Last active June 25, 2017 10:18
Show Gist options
  • Save phdd/60a9bd083cace1fa57c3e28fd1a8e2e0 to your computer and use it in GitHub Desktop.
Save phdd/60a9bd083cace1fa57c3e28fd1a8e2e0 to your computer and use it in GitHub Desktop.
FaaS triggering OwnCloud reload on Dropbox change
'use latest';
import rp from 'request-promise';
import express from 'express';
import bodyParser from 'body-parser';
import { fromExpress } from 'webtask-tools';
const app = express();
app.use(bodyParser.json());
app.get('/', (req, res) => {
const challenge = req.query.challenge || false;
if (challenge)
res.status(200).send(challenge);
else
res.status(400).send('missing challenge query parameter');
});
app.post('/', (req, res) => {
const ownCloud = req.query.ownCloud || false;
if (ownCloud)
rp('https://' + decodeURI(ownCloud) + '/cron.php')
.then(function () {
res.status(200).send();
})
.catch(function (err) {
res.status(400).send(err);
});
else
res.status(400).send('missing ownCloud query parameter');
});
module.exports = fromExpress(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment