Last active
June 25, 2017 10:18
-
-
Save phdd/60a9bd083cace1fa57c3e28fd1a8e2e0 to your computer and use it in GitHub Desktop.
FaaS triggering OwnCloud reload on Dropbox change
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
'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