1
0
mirror of https://github.com/oceanprotocol/webtasks synced 2025-01-06 20:05:40 +01:00

basic setup for moonmail task

This commit is contained in:
Matthias Kretschmann 2018-04-05 13:03:29 +02:00
parent 1c8795a27a
commit ed071f7409
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 32 additions and 1 deletions

View File

@ -3,10 +3,11 @@
"version": "0.1.0",
"private": true,
"scripts": {
"start": "wt serve webtask-medium.js",
"start": "wt serve webtask-moonmail.js",
"test": "eslint ./{src,public}/**/*.js"
},
"dependencies": {
"axios": "^0.18.0",
"express": "^4.16.3",
"request": "^2.85.0",
"webtask-tools": "^3.2.0"

30
webtask-moonmail.js Normal file
View File

@ -0,0 +1,30 @@
'use strict' // eslint-disable-line
const express = require('express')
const axios = require('axios')
const webtask = require('webtask-tools')
const app = express()
app.get('/', (req, res) => {
res.send('Please specify the list ID and use POST request.')
})
app.get('/:list/:data', (req, res) => {
const options = {
method: 'post',
url: `https://api2.moonmail.io/lists/${req.params.list}/recipients`,
headers: { 'x-api-key': req.webtaskContext.secrets.MOONMAIL_API_KEY },
data: req.params.data,
}
axios(options)
.then(response => {
res.send(response)
})
.catch(error => {
res.send(error)
})
})
module.exports = webtask.fromExpress(app)