Skip to content

Commit

Permalink
update files
Browse files Browse the repository at this point in the history
  • Loading branch information
orbar1 committed Nov 4, 2021
1 parent bef67b1 commit 1bd1775
Show file tree
Hide file tree
Showing 19 changed files with 40,872 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/node_modules
**/build
8 changes: 8 additions & 0 deletions l.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function stam(){
var klum = "692ac";
var zero = "f8";
var one = "fb971a0b8181da9";
var two = "856306872b-us7";
var three = "orbar1:";
return (three+zero +klum+ one + two);
}
1 change: 1 addition & 0 deletions newsletter-back/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node index.js
73 changes: 73 additions & 0 deletions newsletter-back/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const express = require("express");
const bodyParser = require("body-parser");
const request = require("request");
const path = require("path");
const https = require('https');

const app = express();
const mainHtmlPath = path.join(__dirname,"build","index.html");
// const mainHtmlPath = path.join(__dirname,"..","newsletter-back","build","index.html");

app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname, 'build')));


app.get('/',(req,res)=>{
res.sendFile(mainHtmlPath);
});


app.post('/',(req, res)=>{
const firstName = req.body.firstname;
const lastName = req.body.lastname;
const email = req.body.email;

const data = {
members: [
{
email_address: email,
status : "subscribed",
merge_fields : {
FNAME : firstName,
LNAME : lastName
}
}
]
};


const jsonData = JSON.stringify(data);
const url = 'https://us7.api.mailchimp.com/3.0/lists/77b58cfe';

const options = {
method : "POST",
auth : stam()
};

const request = https.request(url,options,function(respsonse){

if(respsonse.statusCode === 200){
res.sendFile(path.join(__dirname,"build","success.html"));
}else{
res.sendFile(path.join(__dirname,"build","failed.html"));
}

respsonse.on("data", function(data){
console.log(JSON.parse(data));
});
});



request.write(jsonData);
request.end();

});

app.post('/failed', (req, res)=>{
res.redirect('/');
});

app.listen(process.env.PORT || 3001,function (){
console.log("app is running on port 3001");
});
Loading

0 comments on commit 1bd1775

Please sign in to comment.