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:
parent
1c8795a27a
commit
ed071f7409
@ -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
30
webtask-moonmail.js
Normal 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)
|
Loading…
Reference in New Issue
Block a user