diff --git a/package.json b/package.json index 09a4075..c936aa6 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/webtask-moonmail.js b/webtask-moonmail.js new file mode 100644 index 0000000..0a377e1 --- /dev/null +++ b/webtask-moonmail.js @@ -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)