-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45a6e62
commit 9923dab
Showing
12 changed files
with
1,139 additions
and
1,204 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,23 @@ | ||
var configs = require('./configs'); | ||
var domain = require('domain'); | ||
var dockerExp = /^HTTP response code is (\d\d\d) which indicates an error: (.+)$/; | ||
module.exports = function (parentDomain) { | ||
return function (req, res, next) { | ||
var d = domain.create(); | ||
req.domain = d; | ||
if (parentDomain) { | ||
parentDomain.add(d); | ||
req.parentDomain = parentDomain; | ||
} | ||
d.add(req); | ||
d.add(res); | ||
d.on('error', function (e) { | ||
if (parentDomain && configs.throwErrors && false) { | ||
throw e; | ||
} else if (e.message && dockerExp.test(e.message)) { | ||
var parts = dockerExp.exec(e.message); | ||
var code = parts[1]; | ||
var message = parts[2]; | ||
if (code >= 500) { | ||
code = 502; | ||
} | ||
res.json(code, { message: message }); | ||
} else { | ||
next(e); | ||
module.exports = function (req, res, next) { | ||
var d = domain.create(); | ||
req.domain = d; | ||
d.add(req); | ||
d.add(res); | ||
d.on('error', function (e) { | ||
if (e.message && dockerExp.test(e.message)) { | ||
var parts = dockerExp.exec(e.message); | ||
var code = parts[1]; | ||
var message = parts[2]; | ||
if (code >= 500) { | ||
code = 502; | ||
} | ||
}); | ||
return d.run(next); | ||
}; | ||
res.json(code, { message: message }); | ||
} else { | ||
next(e); | ||
} | ||
}); | ||
d.run(next); | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,50 +4,46 @@ var domains = require('../domains'); | |
var Email = require('email').Email; | ||
var configs = require('../configs'); | ||
var mailchimpApi = configs.mailchimp != null ? new mailchimp.MailChimpAPI(configs.mailchimp.key) : void 0; | ||
module.exports = function (parentDomain) { | ||
var app = express(); | ||
app.use(domains(parentDomain)); | ||
if (mailchimpApi != null) { | ||
Object.keys(configs.mailchimp.lists).forEach(function (list) { | ||
app.post('/campaigns/' + list, function (req, res) { | ||
var opts = { | ||
id: configs.mailchimp.lists[list], | ||
email_address: req.body.EMAIL, | ||
merge_vars: req.body, | ||
send_welcome: false, | ||
update_existing: false, | ||
double_optin: false | ||
}; | ||
mailchimpApi.listSubscribe(opts, function (err) { | ||
if (err) { | ||
res.json(400, { message: err.message }); | ||
} else { | ||
res.json(201, req.body); | ||
} | ||
}); | ||
var app = module.exports = express(); | ||
if (mailchimpApi != null) { | ||
Object.keys(configs.mailchimp.lists).forEach(function (list) { | ||
app.post('/campaigns/' + list, function (req, res) { | ||
var opts = { | ||
id: configs.mailchimp.lists[list], | ||
email_address: req.body.EMAIL, | ||
merge_vars: req.body, | ||
send_welcome: false, | ||
update_existing: false, | ||
double_optin: false | ||
}; | ||
mailchimpApi.listSubscribe(opts, function (err) { | ||
if (err) { | ||
res.json(400, { message: err.message }); | ||
} else { | ||
res.json(201, req.body); | ||
} | ||
}); | ||
}); | ||
} | ||
app.post('/request/improve', function (req, res, next) { | ||
var requestEmailBody = 'Improve Description: \n[\n\t' + req.body.description + '\n]\n\n' + 'sender url: \n[\n\t' + req.body.url + '\n]'; | ||
var requestEmail = new Email({ | ||
from: '[email protected]', | ||
to: '[email protected]', | ||
cc: [ | ||
'[email protected]', | ||
'[email protected]' | ||
], | ||
subject: 'New Improve Request', | ||
body: requestEmailBody | ||
}); | ||
requestEmail.send(function (err) { | ||
if (!err) { | ||
res.json({ response: 'thanks. Will get back to you soon.' }); | ||
} else { | ||
console.error('ERROR sending new request mail', err); | ||
res.json({ response: 'Sorry. Will get back to you soon.' }); | ||
} | ||
}); | ||
}); | ||
return app; | ||
}; | ||
} | ||
app.post('/request/improve', function (req, res, next) { | ||
var requestEmailBody = 'Improve Description: \n[\n\t' + req.body.description + '\n]\n\n' + 'sender url: \n[\n\t' + req.body.url + '\n]'; | ||
var requestEmail = new Email({ | ||
from: '[email protected]', | ||
to: '[email protected]', | ||
cc: [ | ||
'[email protected]', | ||
'[email protected]' | ||
], | ||
subject: 'New Improve Request', | ||
body: requestEmailBody | ||
}); | ||
requestEmail.send(function (err) { | ||
if (!err) { | ||
res.json({ response: 'thanks. Will get back to you soon.' }); | ||
} else { | ||
console.error('ERROR sending new request mail', err); | ||
res.json({ response: 'Sorry. Will get back to you soon.' }); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.