Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
'use strict';

require('dotenv').config();
var fs = require('fs');
var http = require('http');
var https = require('https');
var privateKey = fs.readFileSync('ssl/server.key', 'utf8');
var certificate = fs.readFileSync('ssl/server.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var fs = require('fs'),
http = require('http'),
https = require('https');

/**
* Credentials for MailGun service. Must be stored locally.
* Contact [email protected] with questions.
*/
var privateKey = fs.readFileSync('ssl/server.key', 'utf8'),
certificate = fs.readFileSync('ssl/server.crt', 'utf8'),
credentials = {key: privateKey, cert: certificate};

const express = require('express'),
mg = require('mailgun-js'),
AWS = require('aws-sdk'),
optly = require('optimizely-server-sdk');

const api_key = process.env.MAILGUN_API_KEY,
domain = process.env.MAILGUN_DOMAIN,
AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY,
mailer = mg({apiKey: api_key, domain: domain}),
sender = 'Optimizely <me@' + domain +'>';

//console.log(datafile);

//let optimizely = optly.createInstance({datafile:datafile});

//AWS.config(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY);
//let dynamodb = new AWS.DynamoDB();

const mailer = mg({apiKey: api_key, domain: domain});
const app = express();

const images = {
"shirts": "http://cdn.optimizely.com/img/3546160213/e4aa2777a11542a782be2697e4ca5426.jpg",
"jeans": "http://cdn.optimizely.com/img/3546160213/e4aa2777a11542a782be2697e4ca5426.jpg"

}

const app = express();

app.get('/' , (req,res) => {
res.send('Hello World');
});

app.get('/send', (req,res) => {
let email = req.query.email;

let variationKey = optimizely.activate('email_subjects', email);
//let variationKey = optimizely.activate('email_subjects', email);

let data = {
from: sender,
to: email,
subject: 'Welcome to the Gap',
html: '<html><a href="https://abetterdemo.myshopify.com/#userid=' + email + '"><img src="http://cdn.optimizely.com/img/3546160213/e4aa2777a11542a782be2697e4ca5426.jpg"></a></html>'
html: '<html><a href="https://www.atticandbutton.us/?pid=6878261810#userid=' + email + '"><img src="http://cdn.optimizely.com/img/3546160213/e4aa2777a11542a782be2697e4ca5426.jpg"></a></html>'
}

mailer.messages().send(data, (err, body) => {
Expand All @@ -58,8 +54,8 @@ app.get('/send', (req,res) => {

});

var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
var server = http.createServer(app);
var secureServer = https.createServer(credentials, app);

httpServer.listen(8080);
httpsServer.listen(8443);
server.listen(8080);
secureServer.listen(8443);