'use strict';

/**
 * Module dependencies.
 */
var mailChimp = require('../../node_modules/mailchimp-api/mailchimp'),
	validator = require('../../node_modules/email-validator'),
	config = require('../../config/mc-config.json');

var mc = new mailChimp.Mailchimp(config.apikey);

exports.index = function(req, res) {
	res.render('index', {
		user: req.user || null,
		request: req
	});
};

exports.emailSubscribe = function(req, res) {
	var validEmail = validator.validate(req.params.email);

	if (validEmail) {
		mc.lists.subscribe({id: req.params.listId, email:{email:req.params.email}},
		function(data) {
			res.send({email: req.params.eamil});
		},
		function(error) {
			res.send({email: null, error: 'There was an error subscribing that email.\n' + error.error});
		});
	} else {
		res.send({email: null, error: 'Invalid email address format'});
	}
};

@@ -490,16 +490,56 @@
 ;%0A%0A%09if (
+process.env.NODE_ENV == 'production' && 
 validEma
@@ -821,33 +821,274 @@
 lse 
-%7B%0A%09%09res.send(%7Bemail: null
+if (process.env.NODE_ENV == 'development') %7B%0A%09%09res.send(%7Bemail: null, error: 'This email %22' + req.params.email + '%22 would have been subscribe - but you are hitting a dev server.'%7D);%0A%09%7D else %7B%0A%09%09res.send(%7Bemail: req.params.email + ' - Running on dev - no email sent.'
 , er

Add check to mail subscribe route to only subscribe on production.