-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
19 changed files
with
40,872 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/node_modules | ||
**/build |
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 |
---|---|---|
@@ -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); | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
web: node index.js |
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 |
---|---|---|
@@ -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"); | ||
}); |
Oops, something went wrong.