-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathadd-route.js
More file actions
28 lines (23 loc) · 651 Bytes
/
add-route.js
File metadata and controls
28 lines (23 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const hyperquest = require('hyperquest')
const bl = require('bl')
const qs = require('querystring')
const url = 'https://api.mailgun.net/v3/routes'
function addRoute (domain, description, expression, actions, callback) {
const params = {
description,
expression,
action: actions
}
const data = qs.stringify(params)
const options = {
auth: `api:${process.env.MAILGUN_API_KEY}`,
headers: {
'content-type': 'application/x-www-form-urlencoded',
'content-length': Buffer.byteLength(data)
}
}
const req = hyperquest.post(url, options)
req.pipe(bl(callback))
req.end(data)
}
module.exports = addRoute